Re: [PATCH] can: m_can: fix boolreturn.cocci warnings

2019-10-14 Thread Simon Horman
On Mon, Oct 14, 2019 at 11:04:28PM +0800, kbuild test robot wrote:
> From: kbuild test robot 
> 
> drivers/net/can/m_can/m_can.c:783:9-10: WARNING: return of 0/1 in function 
> 'is_protocol_err' with return type bool
> 
>  Return statements in functions returning bool should use
>  true/false instead of 1/0.
> Generated by: scripts/coccinelle/misc/boolreturn.cocci
> 
> Fixes: 46946163ac61 ("can: m_can: add support for handling arbitration error")
> CC: Pankaj Sharma 
> Signed-off-by: kbuild test robot 
> ---
> 
> url:
> https://github.com/0day-ci/linux/commits/Pankaj-Sharma/can-m_can-add-support-for-handling-arbitration-error/20191014-193532
> 
>  m_can.c |4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -780,9 +780,9 @@ static inline bool is_lec_err(u32 psr)
>  static inline bool is_protocol_err(u32 irqstatus)
>  {
>   if (irqstatus & IR_ERR_LEC_31X)
> - return 1;
> + return true;
>   else
> - return 0;
> + return false;
>  }
>  
>  static int m_can_handle_protocol_error(struct net_device *dev, u32 irqstatus)
> 

<2c>
Perhaps the following is a nicer way to express this (completely untested):

return !!(irqstatus & IR_ERR_LEC_31X);



Re: [PATCH 3/4] watchdog: add meson secure watchdog driver

2019-10-14 Thread Xingyu Chen

Hi, Guenter

On 2019/10/14 21:49, Guenter Roeck wrote:

On 10/14/19 4:42 AM, Xingyu Chen wrote:

Hi, Guenter
Thanks for your review.

On 2019/10/12 22:29, Guenter Roeck wrote:

On 10/12/19 3:05 AM, Xingyu Chen wrote:

The watchdog controller on the Meson-A/C series SoCs is moved to secure
world, watchdog operation needs to be done in secure EL3 mode via ATF,
Non-secure world can call SMC instruction to trap to AFT for watchdog
operation.

Signed-off-by: Xingyu Chen 
---
  drivers/watchdog/Kconfig |  16 +++
  drivers/watchdog/Makefile    |   1 +
  drivers/watchdog/meson_sec_wdt.c | 205 
+++

  3 files changed, 222 insertions(+)
  create mode 100644 drivers/watchdog/meson_sec_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 58e7c10..e6b0707 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -826,6 +826,22 @@ config MESON_GXBB_WATCHDOG
    To compile this driver as a module, choose M here: the
    module will be called meson_gxbb_wdt.
+config MESON_SEC_WATCHDOG
+    tristate "Amlogic Meson Secure watchdog support"
+    depends on ARCH_MESON || COMPILE_TEST


Did you try COMPILE_TEST (eg allmodconfig) on, say x86_64 ?
AFAICS the meson sm calls are only available if MESON_SM is
enabled, and that depends on both ARCH_MESON and ARM64_4K_PAGES.
This dependency is not expressed here, and neither is enabled
with COMPILE_TEST.Sorry, I have't done this kind of test before for 
this patchset. There
is a kernel build error which related to the current driver when i try 
to use allmodconfig with x86. I will fix it by adding "depends on 
MESON_SM" in next version.



+    select WATCHDOG_CORE
+    help
+  The watchdog controller on the Meson-A/C series SoCs is moved to
+  secure world, watchdog operation needs to be done in secure EL3
+  mode via ATF, non-secure world can call SMC instruction to trap
+  to ATF for the watchdog operation.
+
+  Say Y here if watchdog controller on Meson SoCs is located in
+  secure world.
+
+  To compile this driver as a module, choose M here: the
+  module will be called meson_sec_wdt.
+
  config MESON_WATCHDOG
  tristate "Amlogic Meson SoCs watchdog support"
  depends on ARCH_MESON || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 2ee352b..5e6b73d 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_QCOM_WDT) += qcom-wdt.o
  obj-$(CONFIG_BCM_KONA_WDT) += bcm_kona_wdt.o
  obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o
  obj-$(CONFIG_MESON_GXBB_WATCHDOG) += meson_gxbb_wdt.o
+obj-$(CONFIG_MESON_SEC_WATCHDOG) += meson_sec_wdt.o
  obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o
  obj-$(CONFIG_MEDIATEK_WATCHDOG) += mtk_wdt.o
  obj-$(CONFIG_DIGICOLOR_WATCHDOG) += digicolor_wdt.o
diff --git a/drivers/watchdog/meson_sec_wdt.c 
b/drivers/watchdog/meson_sec_wdt.c

new file mode 100644
index ..2b5357c
--- /dev/null
+++ b/drivers/watchdog/meson_sec_wdt.c
@@ -0,0 +1,205 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
+ * Author: Xingyu Chen 
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MESON_SIP_WDT_DISABLE    0x1
+#define MESON_SIP_WDT_ENABLE    0x2
+#define MESON_SIP_WDT_PING    0x3
+#define MESON_SIP_WDT_INIT    0x4
+#define MESON_SIP_WDT_RESETNOW    0x5
+#define MESON_SIP_WDT_SETTIMEOUT    0x6
+#define MESON_SIP_WDT_GETTIMELEFT    0x7
+
+#define DEFAULT_TIMEOUT    30 /* seconds */
+
+/*
+ * Watchdog timer tick is set to 1ms in secfw side, and tick count is
+ * stored in the bit[16-31] of WATCHDOG_CNT register, so the maximum
+ * timeout value is 0x ms.
+ */
+#define MAX_TIMEOUT_MS    0x
+
+struct meson_sec_wdt {
+    struct watchdog_device wdt_dev;
+    struct meson_sm_firmware *fw;
+};
+
+static int meson_sec_wdt_start(struct watchdog_device *wdt_dev)
+{
+    int ret;
+    struct meson_sec_wdt *data = watchdog_get_drvdata(wdt_dev);
+
+    ret = meson_sm_call(data->fw, SM_WATCHDOG_OPS, NULL,
+    MESON_SIP_WDT_ENABLE, 0, 0, 0, 0); > +    if (ret)
+    return ret;
+
+    return 0;


This is equivalent to
 return ret;
or even
 return meson_sm_call(...);
I will fix it in next version.

+}
+
+static int meson_sec_wdt_stop(struct watchdog_device *wdt_dev)
+{
+    int ret;
+    struct meson_sec_wdt *data = watchdog_get_drvdata(wdt_dev);
+
+    ret = meson_sm_call(data->fw, SM_WATCHDOG_OPS, NULL,
+    MESON_SIP_WDT_DISABLE, 0, 0, 0, 0);
+    if (ret)
+    return ret;
+
+    return 0;


Same as above.

I will fix it in next version.



+}
+
+static int meson_sec_wdt_ping(struct watchdog_device *wdt_dev)
+{
+    struct meson_sec_wdt *data = watchdog_get_drvdata(wdt_dev);
+
+    meson_sm_call(data->fw, SM_WATCHDOG_OPS, NULL,
+  MESON_SIP_WDT_PING, 0, 0, 0, 0);
+
+    

Re: SUNRPC: Checking a kmemdup() call in xdr_netobj_dup()

2019-10-14 Thread Markus Elfring
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/sunrpc/xdr.h?id=1c0cc5f1ae5ee5a6913704c0d75a6e99604ee30a#n167
>> https://elixir.bootlin.com/linux/v5.4-rc2/source/include/linux/sunrpc/xdr.h#L167
>>
>> How do you think about to improve it?
>
> On a quick check--I see five xdr_netobj_dup callers, and all of them
> check whether dst->data is NULL.

Your information is appropriate.
https://elixir.bootlin.com/linux/v5.4-rc2/ident/xdr_netobj_dup

Such a Linux source code cross reference can point out that the function 
“xdr_netobj_dup”
is used only within the source file “fs/nfsd/nfs4state.c” so far.


> Sounds like a false positive for your tool?

This depends on the software development view you would prefer here.
The desired null pointer checks are just not performed by the mentioned
(inline) function itself.
I imagine then that a dedicated macro might help to stress software design 
constraints.

Regards,
Markus


Re: [PATCH v9 07/28] x86/boot: Annotate local functions

2019-10-14 Thread Jiri Slaby
On 14. 10. 19, 16:27, Borislav Petkov wrote:
> On Fri, Oct 11, 2019 at 01:50:47PM +0200, Jiri Slaby wrote:
>> .Lrelocated, .Lpaging_enabled, .Lno_longmode, and .Lin_pm32 are
>> self-standing local functions, annotate them as such and preserve "no
>> alignment".
>>
>> The annotations do not generate anything yet.
> 
> So the annotation is only documentational, right?

Right.

thanks,
-- 
js
suse labs


Re: [RFC][PATCH 2/3] usb: roles: Add usb role switch notifier.

2019-10-14 Thread John Stultz
On Thu, Oct 3, 2019 at 1:51 PM Hans de Goede  wrote:
> On 03-10-2019 22:37, John Stultz wrote:
> > Fair point. I'm sort of taking a larger patchset and trying to break
> > it up into more easily reviewable chunks, but I guess here I mis-cut.
> >
> > The user is the hikey960 gpio hub driver here:
> >
> > https://git.linaro.org/people/john.stultz/android-dev.git/commit/?id=b06158a2d3eb00c914f12c76c93695e92d9af00f
>
> Hmm, that seems to tie the TypeC data-role to the power-role, which
> is not going to work with role swapping.

Thanks again for the feedback here. Sorry for the slow response. Been
reworking some of the easier changes but am starting to look at how to
address your feedback here.

> What is controlling the usb-role-switch, and thus ultimately
> causing the notifier you are suggesting to get called ?

The tcpm_mux_set() call via tcpm_state_machine_work()

> Things like TYPEC_VBUS_POWER_OFF and TYPEC_VBUS_POWER_ON
> really beg to be modeled as a regulator and then the
> Type-C controller (using e.g. the drivers/usb/typec/tcpm/tcpm.c
> framework) can use that regulator to control things.
> in case of the tcpm.c framework it can then use that
> regulator to implement the set_vbus callback.

So I'm looking at the bindings and I'm not sure exactly how to tie a
regulator style driver into the tcpm for this?
Looking at the driver I just see this commented out bit:
   
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/typec/tcpm/tcpm.c#n3075

Do you happen to have a pointer to something closer to what you are describing?

thanks
-john


[tip: perf/core] perf evlist: Introduce perf_evlist__mmap_cb_mmap()

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: b80132b12a78ec71de2b3320cc49d4a0b2cd7c46
Gitweb:
https://git.kernel.org/tip/b80132b12a78ec71de2b3320cc49d4a0b2cd7c46
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:28 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:44:59 -03:00

perf evlist: Introduce perf_evlist__mmap_cb_mmap()

Add the perf_evlist__mmap_cb_mmap() function to call perf specific
mmap__mmap() function during perf_evlist__mmap_ops() call.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-21-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f50ee5c..d57b684 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -773,6 +773,16 @@ perf_evlist__mmap_cb_get(struct perf_evlist *_evlist, bool 
overwrite, int idx)
return [idx].core;
 }
 
+static int
+perf_evlist__mmap_cb_mmap(struct perf_mmap *_map, struct perf_mmap_param *_mp,
+ int output, int cpu)
+{
+   struct mmap *map = container_of(_map, struct mmap, core);
+   struct mmap_params *mp = container_of(_mp, struct mmap_params, core);
+
+   return mmap__mmap(map, mp, output, cpu);
+}
+
 static int evlist__mmap_per_cpu(struct evlist *evlist,
 struct mmap_params *mp)
 {
@@ -970,8 +980,9 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int 
pages,
.comp_level = comp_level
};
struct perf_evlist_mmap_ops ops __maybe_unused = {
-   .idx = perf_evlist__mmap_cb_idx,
-   .get = perf_evlist__mmap_cb_get,
+   .idx  = perf_evlist__mmap_cb_idx,
+   .get  = perf_evlist__mmap_cb_get,
+   .mmap = perf_evlist__mmap_cb_mmap,
};
 
if (!evlist->mmap)


[tip: perf/core] libperf: Introduce perf_evlist__exit()

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 93dd6e2831ff399f7685aa2157b997b6392efac8
Gitweb:
https://git.kernel.org/tip/93dd6e2831ff399f7685aa2157b997b6392efac8
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:32 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:56:01 -03:00

libperf: Introduce perf_evlist__exit()

Add the perf_evlist__exit() function, so far it's not exported and added
only for internal use for perf and libperf.

USe it to release cpus/threads and pollfd array.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-25-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 12 +++-
 tools/perf/lib/include/internal/evlist.h |  2 ++
 tools/perf/util/evlist.c |  6 +-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 5ae1da9..7ba98f0 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -109,13 +109,23 @@ perf_evlist__next(struct perf_evlist *evlist, struct 
perf_evsel *prev)
return next;
 }
 
+void perf_evlist__exit(struct perf_evlist *evlist)
+{
+   perf_cpu_map__put(evlist->cpus);
+   perf_thread_map__put(evlist->threads);
+   evlist->cpus = NULL;
+   evlist->threads = NULL;
+   fdarray__exit(>pollfd);
+}
+
 void perf_evlist__delete(struct perf_evlist *evlist)
 {
if (evlist == NULL)
return;
 
perf_evlist__munmap(evlist);
-   fdarray__exit(>pollfd);
+   perf_evlist__close(evlist);
+   perf_evlist__exit(evlist);
free(evlist);
 }
 
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index b201970..0721512 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -48,6 +48,8 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
  struct perf_evlist_mmap_ops *ops,
  struct perf_mmap_param *mp);
 
+void perf_evlist__exit(struct perf_evlist *evlist);
+
 /**
  * __perf_evlist__for_each_entry - iterate thru all the evsels
  * @list: list_head instance to iterate
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 5192c65..031ace3 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -138,7 +138,7 @@ void evlist__exit(struct evlist *evlist)
 {
zfree(>mmap);
zfree(>overwrite_mmap);
-   fdarray__exit(>core.pollfd);
+   perf_evlist__exit(>core);
 }
 
 void evlist__delete(struct evlist *evlist)
@@ -148,10 +148,6 @@ void evlist__delete(struct evlist *evlist)
 
evlist__munmap(evlist);
evlist__close(evlist);
-   perf_cpu_map__put(evlist->core.cpus);
-   perf_thread_map__put(evlist->core.threads);
-   evlist->core.cpus = NULL;
-   evlist->core.threads = NULL;
evlist__purge(evlist);
evlist__exit(evlist);
free(evlist);


Re: [PATCH v1 0/5] perf report: Support sorting all blocks by cycles

2019-10-14 Thread Jin, Yao




On 10/14/2019 11:32 PM, Jiri Olsa wrote:

On Tue, Oct 08, 2019 at 03:04:57PM +0800, Jin Yao wrote:

It would be useful to support sorting for all blocks by the
sampled cycles percent per block. This is useful to concentrate
on the globally busiest/slowest blocks.

This patch series implements a new sort option "total_cycles" which
sorts all blocks by 'Sampled Cycles%'. The 'Sampled Cycles%' is
block sampled cycles aggregation / total sampled cycles

For example,

perf record -b ./div
perf report -s total_cycles --stdio

  # To display the perf.data header info, please use --header/--header-only 
options.
  #
  #
  # Total Lost Samples: 0
  #
  # Samples: 2M of event 'cycles'
  # Event count (approx.): 2753248
  #
  # Sampled Cycles%  Sampled Cycles  Avg Cycles%  Avg Cycles
  [Program Block Range] Shared Object
  # ...  ..  ...  ..  
.  

  #
 26.04%2.8M0.40%  18   
  [div.c:42 -> div.c:39]   div
 15.17%1.2M0.16%   7   
  [random_r.c:357 -> random_r.c:380]  libc-2.27.so
  5.11%  402.0K0.04%   2   
  [div.c:27 -> div.c:28]   div
  4.87%  381.6K0.04%   2   
  [random.c:288 -> random.c:291]  libc-2.27.so
  4.53%  381.0K0.04%   2   
  [div.c:40 -> div.c:40]   div
  3.85%  300.9K0.02%   1   
  [div.c:22 -> div.c:25]   div
  3.08%  241.1K0.02%   1   
[rand.c:26 -> rand.c:27]  libc-2.27.so
  3.06%  240.0K0.02%   1   
  [random.c:291 -> random.c:291]  libc-2.27.so
  2.78%  215.7K0.02%   1   
  [random.c:298 -> random.c:298]  libc-2.27.so
  2.52%  198.3K0.02%   1   
  [random.c:293 -> random.c:293]  libc-2.27.so
  2.36%  184.8K0.02%   1   
[rand.c:28 -> rand.c:28]  libc-2.27.so
  2.33%  180.5K0.02%   1   
  [random.c:295 -> random.c:295]  libc-2.27.so
  2.28%  176.7K0.02%   1   
  [random.c:295 -> random.c:295]  libc-2.27.so
  2.20%  168.8K0.02%   1   
  [rand@plt+0 -> rand@plt+0]   div
  1.98%  158.2K0.02%   1   
  [random_r.c:388 -> random_r.c:388]  libc-2.27.so
  1.57%  123.3K0.02%   1   
  [div.c:42 -> div.c:44]   div
  1.44%  116.0K0.42%  19   
  [random_r.c:357 -> random_r.c:394]  libc-2.27.so
  ..

This patch series supports both stdio and tui. And also with the supporting
of --percent-limit.

Jin Yao (5):
   perf util: Create new block.h/block.c for block related functions
   perf util: Count the total cycles of all samples
   perf report: Sort by sampled cycles percent per block for stdio
   perf report: Support --percent-limit for total_cycles
   perf report: Sort by sampled cycles percent per block for tui


sry for delay, but I can no longer apply this
could you please rebase?

thanks,
jirka



Hi Jiri,

Thanks a lot for reviewing the patch. I just sent out the v2 which had 
been rebased to perf/core branch.


Thanks
Jin Yao



[tip: perf/core] libperf: Introduce perf_evlist__mmap_ops()

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 0b5ea10d4c312f5b17af9d09187efb9418517bec
Gitweb:
https://git.kernel.org/tip/0b5ea10d4c312f5b17af9d09187efb9418517bec
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:22 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:18:00 -03:00

libperf: Introduce perf_evlist__mmap_ops()

To be able to pass specific callbacks to evlist's mmap.

There will be a specific call to this function from perf's
evlist__mmap() and libperf's perf_evlist__mmap() functions in following
changes.

Signed-off-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-15-jo...@kernel.org
Signed-off-by: Jiri Olsa 
---
 tools/perf/lib/evlist.c  | 24 +--
 tools/perf/lib/include/internal/evlist.h |  8 -
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 250ad57..88d63f5 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -472,12 +472,16 @@ out_unmap:
return -1;
 }
 
-int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
+int perf_evlist__mmap_ops(struct perf_evlist *evlist,
+ struct perf_evlist_mmap_ops *ops,
+ struct perf_mmap_param *mp)
 {
struct perf_evsel *evsel;
const struct perf_cpu_map *cpus = evlist->cpus;
const struct perf_thread_map *threads = evlist->threads;
-   struct perf_mmap_param mp;
+
+   if (!ops)
+   return -EINVAL;
 
if (!evlist->mmap)
evlist->mmap = perf_evlist__alloc_mmap(evlist, false);
@@ -491,13 +495,21 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int 
pages)
return -ENOMEM;
}
 
+   if (perf_cpu_map__empty(cpus))
+   return mmap_per_thread(evlist, mp);
+
+   return mmap_per_cpu(evlist, mp);
+}
+
+int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
+{
+   struct perf_mmap_param mp;
+   struct perf_evlist_mmap_ops ops;
+
evlist->mmap_len = (pages + 1) * page_size;
mp.mask = evlist->mmap_len - page_size - 1;
 
-   if (perf_cpu_map__empty(cpus))
-   return mmap_per_thread(evlist, );
-
-   return mmap_per_cpu(evlist, );
+   return perf_evlist__mmap_ops(evlist, , );
 }
 
 void perf_evlist__munmap(struct perf_evlist *evlist)
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index 4438a19..e5f092f 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -11,6 +11,7 @@
 
 struct perf_cpu_map;
 struct perf_thread_map;
+struct perf_mmap_param;
 
 struct perf_evlist {
struct list_head entries;
@@ -26,10 +27,17 @@ struct perf_evlist {
struct perf_mmap*mmap_ovw;
 };
 
+struct perf_evlist_mmap_ops {
+};
+
 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
 int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
void *ptr, short revent);
 
+int perf_evlist__mmap_ops(struct perf_evlist *evlist,
+ struct perf_evlist_mmap_ops *ops,
+ struct perf_mmap_param *mp);
+
 /**
  * __perf_evlist__for_each_entry - iterate thru all the evsels
  * @list: list_head instance to iterate


[tip: perf/core] perf trace: Add a strtoul() method to 'struct syscall_arg_fmt'

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 3f41b77843b338e836f52cc2d486be689d6cb9c1
Gitweb:
https://git.kernel.org/tip/3f41b77843b338e836f52cc2d486be689d6cb9c1
Author:Arnaldo Carvalho de Melo 
AuthorDate:Wed, 09 Oct 2019 16:06:43 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 16:06:43 -03:00

perf trace: Add a strtoul() method to 'struct syscall_arg_fmt'

This will go from a string to a number, so that filter expressions can
be constructed with strings and then, before applying the tracepoint
filters (or eBPF, in the future) we can map those strings to numbers.

The first one will be for 'msr' tracepoint arguments, but real quickly
we will be able to reuse all strarrays for that.

Cc: Adrian Hunter 
Cc: Brendan Gregg 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-wgqq48agcgr95b8dmn6fy...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 2c19680..faa5bf4 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -86,8 +86,12 @@
 # define F_LINUX_SPECIFIC_BASE 1024
 #endif
 
+/*
+ * strtoul: Go from a string to a value, i.e. for msr: MSR_FS_BASE to 
0xc100
+ */
 struct syscall_arg_fmt {
size_t (*scnprintf)(char *bf, size_t size, struct syscall_arg *arg);
+   bool   (*strtoul)(char *bf, size_t size, struct syscall_arg *arg, 
u64 *val);
unsigned long (*mask_val)(struct syscall_arg *arg, unsigned long val);
void   *parm;
const char *name;
@@ -1543,8 +1547,10 @@ syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, 
struct tep_format_field
} else {
struct syscall_arg_fmt *fmt = 
syscall_arg_fmt__find_by_name(field->name);
 
-   if (fmt)
+   if (fmt) {
arg->scnprintf = fmt->scnprintf;
+   arg->strtoul   = fmt->strtoul;
+   }
}
}
 


[tip: perf/core] perf tools: Use perf_mmap way to detect aux mmap

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 1d40ae4e1784bfa1646fd153ca022db21511284f
Gitweb:
https://git.kernel.org/tip/1d40ae4e1784bfa1646fd153ca022db21511284f
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:16 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 10:11:54 -03:00

perf tools: Use perf_mmap way to detect aux mmap

We will move this code to libperf shortly, so we need to free it of
'struct auxtrace_mmap' usage, because it won't be available in libperf
(for now).

The perf_event_mmap_page::aux_size is set when the aux mmap is mapped,
so the check is equivalent.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-9-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/mmap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 9f150d5..f246dd4 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -107,7 +107,9 @@ union perf_event *perf_mmap__read_event(struct mmap *map)
 
 static bool perf_mmap__empty(struct mmap *map)
 {
-   return perf_mmap__read_head(map) == map->core.prev && 
!map->auxtrace_mmap.base;
+   struct perf_event_mmap_page *pc = map->core.base;
+
+   return perf_mmap__read_head(map) == map->core.prev && !pc->aux_size;
 }
 
 void perf_mmap__consume(struct mmap *map)


[tip: perf/core] libperf: Adopt perf_mmap__get() function from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: e75710f063e29ae7715c57b45eb27c2d504b32ca
Gitweb:
https://git.kernel.org/tip/e75710f063e29ae7715c57b45eb27c2d504b32ca
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:13 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 09:53:27 -03:00

libperf: Adopt perf_mmap__get() function from tools/perf

Move perf_mmap__get() from tools/perf to libperf in the internal header
internal/mmap.h.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-6-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c| 2 +-
 tools/perf/lib/include/internal/mmap.h | 1 +
 tools/perf/lib/mmap.c  | 5 +
 tools/perf/util/evlist.c   | 2 +-
 tools/perf/util/mmap.c | 5 -
 tools/perf/util/mmap.h | 1 -
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f05e8b7..025a12b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -293,7 +293,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, 
void *buf, size_t size
 * after started aio request completion or at record__aio_push()
 * if the request failed to start.
 */
-   perf_mmap__get(map);
+   perf_mmap__get(>core);
}
 
aio->size += size;
diff --git a/tools/perf/lib/include/internal/mmap.h 
b/tools/perf/lib/include/internal/mmap.h
index 7067b70..2e68974 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -39,5 +39,6 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map);
 void perf_mmap__init(struct perf_mmap *map, bool overwrite);
 int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, int cpu);
+void perf_mmap__get(struct perf_mmap *map);
 
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index b216a7d..b765e05 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -31,3 +31,8 @@ int perf_mmap__mmap(struct perf_mmap *map, struct 
perf_mmap_param *mp,
map->cpu = cpu;
return 0;
 }
+
+void perf_mmap__get(struct perf_mmap *map)
+{
+   refcount_inc(>refcnt);
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f9781de..dc5b360 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -701,7 +701,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, 
int idx,
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
return -1;
 
-   perf_mmap__get([idx]);
+   perf_mmap__get([idx].core);
}
 
revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index acef6e3..be691b5 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -110,11 +110,6 @@ static bool perf_mmap__empty(struct mmap *map)
return perf_mmap__read_head(map) == map->core.prev && 
!map->auxtrace_mmap.base;
 }
 
-void perf_mmap__get(struct mmap *map)
-{
-   refcount_inc(>core.refcnt);
-}
-
 void perf_mmap__put(struct mmap *map)
 {
BUG_ON(map->core.base && refcount_read(>core.refcnt) == 0);
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index a60e6ea..a73402e 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -45,7 +45,6 @@ struct mmap_params {
 int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
 void perf_mmap__munmap(struct mmap *map);
 
-void perf_mmap__get(struct mmap *map);
 void perf_mmap__put(struct mmap *map);
 
 void perf_mmap__consume(struct mmap *map);


[tip: perf/core] libperf: Adopt perf_mmap__consume() function from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 7728fa0cfaeb7d25b12c8865c733359cc8e5fb13
Gitweb:
https://git.kernel.org/tip/7728fa0cfaeb7d25b12c8865c733359cc8e5fb13
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:17 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 11:43:49 -03:00

libperf: Adopt perf_mmap__consume() function from tools/perf

Move perf_mmap__consume() vrom tools/perf to libperf and export it in
the perf/mmap.h header.

Move also the needed helpers perf_mmap__write_tail(),
perf_mmap__read_head() and perf_mmap__empty().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-10-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |  3 +-
 tools/perf/builtin-kvm.c |  5 +--
 tools/perf/builtin-top.c |  3 +-
 tools/perf/builtin-trace.c   |  3 +-
 tools/perf/lib/Makefile  |  5 +--
 tools/perf/lib/include/internal/mmap.h   |  2 +-
 tools/perf/lib/include/perf/mmap.h   | 11 +++-
 tools/perf/lib/libperf.map   |  1 +-
 tools/perf/lib/mmap.c| 32 +++-
 tools/perf/tests/backward-ring-buffer.c  |  1 +-
 tools/perf/tests/bpf.c   |  1 +-
 tools/perf/tests/code-reading.c  |  3 +-
 tools/perf/tests/keep-tracking.c |  3 +-
 tools/perf/tests/mmap-basic.c|  3 +-
 tools/perf/tests/openat-syscall-tp-fields.c  |  3 +-
 tools/perf/tests/perf-record.c   |  3 +-
 tools/perf/tests/sw-clock.c  |  3 +-
 tools/perf/tests/switch-tracking.c   |  3 +-
 tools/perf/tests/task-exit.c |  3 +-
 tools/perf/util/evlist.c |  3 +-
 tools/perf/util/mmap.c   | 32 ---
 tools/perf/util/mmap.h   | 12 +---
 tools/perf/util/python.c |  3 +-
 23 files changed, 87 insertions(+), 54 deletions(-)
 create mode 100644 tools/perf/lib/include/perf/mmap.h

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 fa94795..3397898 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "debug.h"
 #include "parse-events.h"
@@ -139,7 +140,7 @@ int test__perf_time_to_tsc(struct test *test 
__maybe_unused, int subtest __maybe
comm2_time = sample.time;
}
 next_event:
-   perf_mmap__consume(md);
+   perf_mmap__consume(>core);
}
perf_mmap__read_done(md);
}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 58a9e09..0c04c4c 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -46,6 +46,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static const char *get_filename_for_perf_kvm(void)
 {
@@ -766,7 +767,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat 
*kvm, int idx,
while ((event = perf_mmap__read_event(md)) != NULL) {
err = perf_evlist__parse_sample_timestamp(evlist, event, 
);
if (err) {
-   perf_mmap__consume(md);
+   perf_mmap__consume(>core);
pr_err("Failed to parse sample\n");
return -1;
}
@@ -776,7 +777,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat 
*kvm, int idx,
 * FIXME: Here we can't consume the event, as 
perf_session__queue_event will
 *point to it, and it'll get possibly overwritten by 
the kernel.
 */
-   perf_mmap__consume(md);
+   perf_mmap__consume(>core);
 
if (err) {
pr_err("Failed to enqueue sample: %d\n", err);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 611d030..5fcf157 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -82,6 +82,7 @@
 #include 
 
 #include 
+#include 
 
 static volatile int done;
 static volatile int resize;
@@ -883,7 +884,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, 
int idx)
if (ret)
break;
 
-   perf_mmap__consume(md);
+   perf_mmap__consume(>core);
 
if (top->qe.rotate) {
pthread_mutex_lock(>qe.mutex);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index b627975..6a57084 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -77,6 +77,7 @@
 #include 
 
 

[tip: perf/core] libperf: Introduce perf_evlist_mmap_ops::idx callback

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 1fcbb75cc574072ab457dbbaa74fc7064b691e86
Gitweb:
https://git.kernel.org/tip/1fcbb75cc574072ab457dbbaa74fc7064b691e86
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:23 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:20:08 -03:00

libperf: Introduce perf_evlist_mmap_ops::idx callback

Add the perf_evlist_mmap_ops::idx callback to be called in
mmap_per_cpu() and mmap_per_thread() with current cpu and thread
indexes.

It's used by current aux code, so perf will use this callback to set the
aux index.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-16-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 18 +-
 tools/perf/lib/include/internal/evlist.h |  4 
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 88d63f5..3832d3e 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -426,7 +426,8 @@ mmap_per_evsel(struct perf_evlist *evlist, int idx,
 }
 
 static int
-mmap_per_thread(struct perf_evlist *evlist, struct perf_mmap_param *mp)
+mmap_per_thread(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
+   struct perf_mmap_param *mp)
 {
int thread;
int nr_threads = perf_thread_map__nr(evlist->threads);
@@ -435,6 +436,9 @@ mmap_per_thread(struct perf_evlist *evlist, struct 
perf_mmap_param *mp)
int output = -1;
int output_overwrite = -1;
 
+   if (ops->idx)
+   ops->idx(evlist, mp, thread, false);
+
if (mmap_per_evsel(evlist, thread, mp, 0, thread,
   , _overwrite))
goto out_unmap;
@@ -448,7 +452,8 @@ out_unmap:
 }
 
 static int
-mmap_per_cpu(struct perf_evlist *evlist, struct perf_mmap_param *mp)
+mmap_per_cpu(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
+struct perf_mmap_param *mp)
 {
int nr_threads = perf_thread_map__nr(evlist->threads);
int nr_cpus= perf_cpu_map__nr(evlist->cpus);
@@ -458,6 +463,9 @@ mmap_per_cpu(struct perf_evlist *evlist, struct 
perf_mmap_param *mp)
int output = -1;
int output_overwrite = -1;
 
+   if (ops->idx)
+   ops->idx(evlist, mp, cpu, true);
+
for (thread = 0; thread < nr_threads; thread++) {
if (mmap_per_evsel(evlist, cpu, mp, cpu,
   thread, , _overwrite))
@@ -496,15 +504,15 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
}
 
if (perf_cpu_map__empty(cpus))
-   return mmap_per_thread(evlist, mp);
+   return mmap_per_thread(evlist, ops, mp);
 
-   return mmap_per_cpu(evlist, mp);
+   return mmap_per_cpu(evlist, ops, mp);
 }
 
 int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
 {
struct perf_mmap_param mp;
-   struct perf_evlist_mmap_ops ops;
+   struct perf_evlist_mmap_ops ops = { 0 };
 
evlist->mmap_len = (pages + 1) * page_size;
mp.mask = evlist->mmap_len - page_size - 1;
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index e5f092f..053f620 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -27,7 +27,11 @@ struct perf_evlist {
struct perf_mmap*mmap_ovw;
 };
 
+typedef void
+(*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, 
int, bool);
+
 struct perf_evlist_mmap_ops {
+   perf_evlist_mmap__cb_idx_t  idx;
 };
 
 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);


[tip: perf/core] perf evlist: Switch to libperf's mmap interface

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 923d0f1868cb331d660fb569ecd00c39889905f6
Gitweb:
https://git.kernel.org/tip/923d0f1868cb331d660fb569ecd00c39889905f6
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:29 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:46:04 -03:00

perf evlist: Switch to libperf's mmap interface

Switch to the libperf mmap interface by calling directly
perf_evlist__mmap_ops() and removing perf's evlist__mmap_per_*
functions.

By switching to libperf perf_evlist__mmap() we need to operate over
'struct perf_mmap' in evlist__add_pollfd, so make the related changes
there.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-22-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 179 +--
 1 file changed, 4 insertions(+), 175 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index d57b684..3f4f11f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -431,10 +431,10 @@ int evlist__add_pollfd(struct evlist *evlist, int fd)
 static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
 void *arg __maybe_unused)
 {
-   struct mmap *map = fda->priv[fd].ptr;
+   struct perf_mmap *map = fda->priv[fd].ptr;
 
if (map)
-   perf_mmap__put(>core);
+   perf_mmap__put(map);
 }
 
 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
@@ -448,22 +448,6 @@ int evlist__poll(struct evlist *evlist, int timeout)
return perf_evlist__poll(>core, timeout);
 }
 
-static void perf_evlist__set_sid_idx(struct evlist *evlist,
-struct evsel *evsel, int idx, int cpu,
-int thread)
-{
-   struct perf_sample_id *sid = SID(evsel, cpu, thread);
-   sid->idx = idx;
-   if (evlist->core.cpus && cpu >= 0)
-   sid->cpu = evlist->core.cpus->map[cpu];
-   else
-   sid->cpu = -1;
-   if (!evsel->core.system_wide && evlist->core.threads && thread >= 0)
-   sid->tid = perf_thread_map__pid(evlist->core.threads, thread);
-   else
-   sid->tid = -1;
-}
-
 struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id)
 {
struct hlist_head *head;
@@ -652,93 +636,6 @@ static struct mmap *evlist__alloc_mmap(struct evlist 
*evlist,
return map;
 }
 
-static bool
-perf_evlist__should_poll(struct evlist *evlist __maybe_unused,
-struct evsel *evsel)
-{
-   if (evsel->core.attr.write_backward)
-   return false;
-   return true;
-}
-
-static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
-  struct mmap_params *mp, int cpu_idx,
-  int thread, int *_output, int 
*_output_overwrite)
-{
-   struct evsel *evsel;
-   int revent;
-   int evlist_cpu = cpu_map__cpu(evlist->core.cpus, cpu_idx);
-
-   evlist__for_each_entry(evlist, evsel) {
-   struct mmap *maps = evlist->mmap;
-   int *output = _output;
-   int fd;
-   int cpu;
-
-   mp->core.prot = PROT_READ | PROT_WRITE;
-   if (evsel->core.attr.write_backward) {
-   output = _output_overwrite;
-   maps = evlist->overwrite_mmap;
-
-   if (!maps) {
-   maps = evlist__alloc_mmap(evlist, true);
-   if (!maps)
-   return -1;
-   evlist->overwrite_mmap = maps;
-   if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
-   perf_evlist__toggle_bkw_mmap(evlist, 
BKW_MMAP_RUNNING);
-   }
-   mp->core.prot &= ~PROT_WRITE;
-   }
-
-   if (evsel->core.system_wide && thread)
-   continue;
-
-   cpu = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu);
-   if (cpu == -1)
-   continue;
-
-   fd = FD(evsel, cpu, thread);
-
-   if (*output == -1) {
-   *output = fd;
-
-   if (mmap__mmap([idx], mp, *output, evlist_cpu) < 0)
-   return -1;
-   } else {
-   if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
-   return -1;
-
-   perf_mmap__get([idx].core);
-   }
-
-   revent = perf_evlist__should_poll(evlist, evsel) ? POLLIN : 0;
-
-   

[tip: perf/core] perf evlist: Introduce perf_evlist__mmap_cb_get()

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: bb1b1885e2f22afb8bc7981cd865fe4b0e3d975b
Gitweb:
https://git.kernel.org/tip/bb1b1885e2f22afb8bc7981cd865fe4b0e3d975b
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:27 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:30:21 -03:00

perf evlist: Introduce perf_evlist__mmap_cb_get()

Add the perf_evlist__mmap_cb_get() function to return 'struct perf_mmap'
object during perf_evlist__mmap_ops() call.

The array of 'struct mmap' is allocated via evlist__alloc_mmap(), in
this callback we simply returns pointer to the base object.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-20-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 11716f2..f50ee5c 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -750,6 +750,29 @@ perf_evlist__mmap_cb_idx(struct perf_evlist *_evlist,
auxtrace_mmap_params__set_idx(>auxtrace_mp, evlist, idx, per_cpu);
 }
 
+static struct perf_mmap*
+perf_evlist__mmap_cb_get(struct perf_evlist *_evlist, bool overwrite, int idx)
+{
+   struct evlist *evlist = container_of(_evlist, struct evlist, core);
+   struct mmap *maps = evlist->mmap;
+
+   if (overwrite) {
+   maps = evlist->overwrite_mmap;
+
+   if (!maps) {
+   maps = evlist__alloc_mmap(evlist, true);
+   if (!maps)
+   return NULL;
+
+   evlist->overwrite_mmap = maps;
+   if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
+   perf_evlist__toggle_bkw_mmap(evlist, 
BKW_MMAP_RUNNING);
+   }
+   }
+
+   return [idx].core;
+}
+
 static int evlist__mmap_per_cpu(struct evlist *evlist,
 struct mmap_params *mp)
 {
@@ -948,6 +971,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int 
pages,
};
struct perf_evlist_mmap_ops ops __maybe_unused = {
.idx = perf_evlist__mmap_cb_idx,
+   .get = perf_evlist__mmap_cb_get,
};
 
if (!evlist->mmap)


[tip: perf/core] libperf: Centralize map refcnt setting

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 285aaeac8c5d537b56b70169e21ac29ae5caa8e1
Gitweb:
https://git.kernel.org/tip/285aaeac8c5d537b56b70169e21ac29ae5caa8e1
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:30 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:52:41 -03:00

libperf: Centralize map refcnt setting

Currently when a new map is mmapped we set its refcnt to 2 in the
perf_evlist_mmap_ops::mmap callback.

Every mmap gets its refcnt set to 2 when it's first mmaped:

  - 1 for the current user, which will be taken out by a call to
perf_evlist__munmap_filtered(), where we find out there's
no more data comming from kernel to this mmap.

  - 1 for the drain code where in perf_mmap__consume() the mmap
is released if it is empty.

Move this common setup into libperf's generic code before the mmap
callback is called.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-23-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c | 30 +++---
 tools/perf/util/mmap.c  | 15 ---
 2 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index b697226..f9a802d 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -362,21 +362,6 @@ static int
 perf_evlist__mmap_cb_mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
  int output, int cpu)
 {
-   /*
-* The last one will be done at perf_mmap__consume(), so that we
-* make sure we don't prevent tools from consuming every last event in
-* the ring buffer.
-*
-* I.e. we can get the POLLHUP meaning that the fd doesn't exist
-* anymore, but the last events for it are still in the ring buffer,
-* waiting to be consumed.
-*
-* Tools can chose to ignore this at their own discretion, but the
-* evlist layer can't just drop it when filtering events in
-* perf_evlist__filter_pollfd().
-*/
-   refcount_set(>refcnt, 2);
-
return perf_mmap__mmap(map, mp, output, cpu);
 }
 
@@ -418,6 +403,21 @@ mmap_per_evsel(struct perf_evlist *evlist, struct 
perf_evlist_mmap_ops *ops,
if (*output == -1) {
*output = fd;
 
+   /*
+* The last one will be done at perf_mmap__consume(), 
so that we
+* make sure we don't prevent tools from consuming 
every last event in
+* the ring buffer.
+*
+* I.e. we can get the POLLHUP meaning that the fd 
doesn't exist
+* anymore, but the last events for it are still in the 
ring buffer,
+* waiting to be consumed.
+*
+* Tools can chose to ignore this at their own 
discretion, but the
+* evlist layer can't just drop it when filtering 
events in
+* perf_evlist__filter_pollfd().
+*/
+   refcount_set(>refcnt, 2);
+
if (ops->mmap(map, mp, *output, evlist_cpu) < 0)
return -1;
} else {
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 2a8bf0a..063d1b9 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -243,21 +243,6 @@ static void perf_mmap__setup_affinity_mask(struct mmap 
*map, struct mmap_params 
 
 int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
 {
-   /*
-* The last one will be done at perf_mmap__consume(), so that we
-* make sure we don't prevent tools from consuming every last event in
-* the ring buffer.
-*
-* I.e. we can get the POLLHUP meaning that the fd doesn't exist
-* anymore, but the last events for it are still in the ring buffer,
-* waiting to be consumed.
-*
-* Tools can chose to ignore this at their own discretion, but the
-* evlist layer can't just drop it when filtering events in
-* perf_evlist__filter_pollfd().
-*/
-   refcount_set(>core.refcnt, 2);
-
if (perf_mmap__mmap(>core, >core, fd, cpu)) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
  errno);


[tip: perf/core] perf trace: Expand strings in filters to integers

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 90df0249c2eae21f329760ee857575260926188a
Gitweb:
https://git.kernel.org/tip/90df0249c2eae21f329760ee857575260926188a
Author:Arnaldo Carvalho de Melo 
AuthorDate:Wed, 09 Oct 2019 16:22:16 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 16:22:16 -03:00

perf trace: Expand strings in filters to integers

So that one can try things like:

  # perf trace -e msr:* --filter="msr!=FS_BASE && msr != IA32_TSC_DEADLINE && 
msr != 0x830 && msr != 0x83f && msr !=IA32_SPEC_CTRL" --filter-pids 3750

That, at this point in the patchset, without any strtoul in place for
tracepoint arguments, will result in:

  No resolver (strtoul) for "msr" in "msr:read_msr", can't set filter 
"(msr!=FS_BASE && msr != IA32_TSC_DEADLINE && msr != 0x830 && msr != 0x83f && 
msr !=IA32_SPEC_CTRL) && (common_pid != 25407 && common_pid != 3750)"
  #

See you in the next cset!

Cc: Adrian Hunter 
Cc: Brendan Gregg 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-dx5j70fv2rgkeezd1cb3h...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 130 -
 1 file changed, 130 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 50a1aeb..515a800 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3484,6 +3484,133 @@ static int ordered_events__deliver_event(struct 
ordered_events *oe,
return __trace__deliver_event(trace, event->event);
 }
 
+static struct syscall_arg_fmt *perf_evsel__syscall_arg_fmt(struct evsel 
*evsel, char *arg)
+{
+   struct tep_format_field *field;
+   struct syscall_arg_fmt *fmt = evsel->priv;
+
+   if (evsel->tp_format == NULL || fmt == NULL)
+   return NULL;
+
+   for (field = evsel->tp_format->format.fields; field; field = 
field->next, ++fmt)
+   if (strcmp(field->name, arg) == 0)
+   return fmt;
+
+   return NULL;
+}
+
+static int trace__expand_filter(struct trace *trace __maybe_unused, struct 
evsel *evsel)
+{
+   char *tok, *left = evsel->filter, *new_filter = evsel->filter;
+
+   while ((tok = strpbrk(left, "=<>!")) != NULL) {
+   char *right = tok + 1, *right_end;
+
+   if (*right == '=')
+   ++right;
+
+   while (isspace(*right))
+   ++right;
+
+   if (*right == '\0')
+   break;
+
+   while (!isalpha(*left))
+   if (++left == tok) {
+   /*
+* Bail out, can't find the name of the 
argument that is being
+* used in the filter, let it try to set this 
filter, will fail later.
+*/
+   return 0;
+   }
+
+   right_end = right + 1;
+   while (isalnum(*right_end) || *right_end == '_')
+   ++right_end;
+
+   if (isalpha(*right)) {
+   struct syscall_arg_fmt *fmt;
+   int left_size = tok - left,
+   right_size = right_end - right;
+   char arg[128];
+
+   while (isspace(left[left_size - 1]))
+   --left_size;
+
+   scnprintf(arg, sizeof(arg), "%.*s", left_size, left);
+
+   fmt = perf_evsel__syscall_arg_fmt(evsel, arg);
+   if (fmt == NULL) {
+   pr_debug("\"%s\" not found in \"%s\", can't set 
filter \"%s\"\n",
+arg, evsel->name, evsel->filter);
+   return -1;
+   }
+
+   pr_debug2("trying to expand \"%s\" \"%.*s\" \"%.*s\" -> 
",
+arg, (int)(right - tok), tok, right_size, 
right);
+
+   if (fmt->strtoul) {
+   u64 val;
+   if (fmt->strtoul(right, right_size, NULL, 
)) {
+   char *n, expansion[19];
+   int expansion_lenght = 
scnprintf(expansion, sizeof(expansion), "%#" PRIx64, val);
+   int expansion_offset = right - 
new_filter;
+
+   pr_debug("%s", expansion);
+
+   if (asprintf(, "%.*s%s%s", 
expansion_offset, new_filter, expansion, right_end) < 0) {
+   pr_debug(" out of memory!\n");
+   free(new_filter);
+   return -1;
+

[tip: perf/core] libperf: Adopt perf_mmap__read_init() from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 7c4d41824f9afc659ba425a41018546531cffd72
Gitweb:
https://git.kernel.org/tip/7c4d41824f9afc659ba425a41018546531cffd72
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:18 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 11:45:21 -03:00

libperf: Adopt perf_mmap__read_init() from tools/perf

Move perf_mmap__read_init() from tools/perf to libperf and export it in
perf/mmap.h header.

And add pr_debug2()/pr_debug3() macros support, because the code is
using them.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-11-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |  2 +-
 tools/perf/builtin-kvm.c |  2 +-
 tools/perf/builtin-top.c |  2 +-
 tools/perf/builtin-trace.c   |  2 +-
 tools/perf/lib/include/perf/core.h   |  2 +-
 tools/perf/lib/include/perf/mmap.h   |  1 +-
 tools/perf/lib/internal.h|  2 +-
 tools/perf/lib/libperf.map   |  1 +-
 tools/perf/lib/mmap.c| 84 +++-
 tools/perf/tests/backward-ring-buffer.c  |  2 +-
 tools/perf/tests/bpf.c   |  2 +-
 tools/perf/tests/code-reading.c  |  2 +-
 tools/perf/tests/keep-tracking.c |  2 +-
 tools/perf/tests/mmap-basic.c|  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c  |  2 +-
 tools/perf/tests/perf-record.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/util/evlist.c |  2 +-
 tools/perf/util/mmap.c   | 82 +---
 tools/perf/util/mmap.h   |  1 +-
 tools/perf/util/python.c |  2 +-
 23 files changed, 107 insertions(+), 98 deletions(-)

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 3397898..6a0c3ff 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -118,7 +118,7 @@ int test__perf_time_to_tsc(struct test *test 
__maybe_unused, int subtest __maybe
 
for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = >mmap[i];
-   if (perf_mmap__read_init(md) < 0)
+   if (perf_mmap__read_init(>core) < 0)
continue;
 
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 0c04c4c..b6a8078 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -760,7 +760,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat 
*kvm, int idx,
 
*mmap_time = ULLONG_MAX;
md = >mmap[idx];
-   err = perf_mmap__read_init(md);
+   err = perf_mmap__read_init(>core);
if (err < 0)
return (err == -EAGAIN) ? 0 : -1;
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 5fcf157..4a4bb7b 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -870,7 +870,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, 
int idx)
union perf_event *event;
 
md = opts->overwrite ? >overwrite_mmap[idx] : 
>mmap[idx];
-   if (perf_mmap__read_init(md) < 0)
+   if (perf_mmap__read_init(>core) < 0)
return;
 
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6a57084..cd69d68 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3801,7 +3801,7 @@ again:
struct mmap *md;
 
md = >mmap[i];
-   if (perf_mmap__read_init(md) < 0)
+   if (perf_mmap__read_init(>core) < 0)
continue;
 
while ((event = perf_mmap__read_event(md)) != NULL) {
diff --git a/tools/perf/lib/include/perf/core.h 
b/tools/perf/lib/include/perf/core.h
index cfd70e7..2a80e4b 100644
--- a/tools/perf/lib/include/perf/core.h
+++ b/tools/perf/lib/include/perf/core.h
@@ -12,6 +12,8 @@ enum libperf_print_level {
LIBPERF_WARN,
LIBPERF_INFO,
LIBPERF_DEBUG,
+   LIBPERF_DEBUG2,
+   LIBPERF_DEBUG3,
 };
 
 typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
diff --git a/tools/perf/lib/include/perf/mmap.h 
b/tools/perf/lib/include/perf/mmap.h
index d3678d1..646e905 100644
--- a/tools/perf/lib/include/perf/mmap.h
+++ b/tools/perf/lib/include/perf/mmap.h
@@ -7,5 +7,6 @@
 struct perf_mmap;
 
 LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
+LIBPERF_API 

[tip: perf/core] perf trace: Introduce a strtoul() method for 'struct strarrays'

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: d0a3a1041005d9273d18669819e2a6dfed922a4d
Gitweb:
https://git.kernel.org/tip/d0a3a1041005d9273d18669819e2a6dfed922a4d
Author:Arnaldo Carvalho de Melo 
AuthorDate:Wed, 09 Oct 2019 16:11:36 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 16:11:36 -03:00

perf trace: Introduce a strtoul() method for 'struct strarrays'

And also for 'struct strarray', since its needed to implement
strarrays__strtoul(). This just traverses the entries and when finding a
match, returns (offset + index), i.e. the value associated with the
searched string.

E.g. "EFER" (MSR_EFER) returns:

  # grep -w EFER -B2 
/tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
  #define x86_64_specific_MSRs_offset 0xc080
  static const char *x86_64_specific_MSRs[] = {
[0xc080 - x86_64_specific_MSRs_offset] = "EFER",
  #

  0xc080

This will be auto-attached to 'struct syscall_arg_fmt' entries
associated with strarrays as soon as we add a ->strarray and ->strarrays
to 'struct syscall_arg_fmt'.

Cc: Adrian Hunter 
Cc: Brendan Gregg 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-r2hpaahf8lishyb1owko9...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c   | 28 
 tools/perf/trace/beauty/beauty.h |  5 +
 2 files changed, 33 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index faa5bf4..50a1aeb 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -477,6 +477,34 @@ size_t strarrays__scnprintf(struct strarrays *sas, char 
*bf, size_t size, const 
return printed;
 }
 
+bool strarray__strtoul(struct strarray *sa, char *bf, size_t size, u64 *ret)
+{
+   int i;
+
+   for (i = 0; i < sa->nr_entries; ++i) {
+   if (sa->entries[i] && strncmp(sa->entries[i], bf, size) == 0 && 
sa->entries[i][size] == '\0') {
+   *ret = sa->offset + i;
+   return true;
+   }
+   }
+
+   return false;
+}
+
+bool strarrays__strtoul(struct strarrays *sas, char *bf, size_t size, u64 *ret)
+{
+   int i;
+
+   for (i = 0; i < sas->nr_entries; ++i) {
+   struct strarray *sa = sas->entries[i];
+
+   if (strarray__strtoul(sa, bf, size, ret))
+   return true;
+   }
+
+   return false;
+}
+
 size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size,
struct syscall_arg *arg)
 {
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index aa3fac8..919ac45 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct strarray {
u64 offset;
@@ -29,6 +30,8 @@ struct strarray {
 size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const 
char *intfmt, bool show_prefix, int val);
 size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, 
bool show_prefix, unsigned long flags);
 
+bool strarray__strtoul(struct strarray *sa, char *bf, size_t size, u64 *ret);
+
 struct trace;
 struct thread;
 
@@ -51,6 +54,8 @@ struct strarrays {
 
 size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, 
const char *intfmt, bool show_prefix, int val);
 
+bool strarrays__strtoul(struct strarrays *sas, char *bf, size_t size, u64 
*ret);
+
 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, 
size_t size);
 
 extern struct strarray strarray__socket_families;


[tip: perf/core] libperf: Adopt perf_mmap__read_event() from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 151ed5d70da87720022e4171227733a008b3c719
Gitweb:
https://git.kernel.org/tip/151ed5d70da87720022e4171227733a008b3c719
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:20 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 11:49:46 -03:00

libperf: Adopt perf_mmap__read_event() from tools/perf

Move perf_mmap__read_event() from tools/perf to libperf and export it in
the perf/mmap.h header.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-13-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |  2 +-
 tools/perf/builtin-kvm.c |  2 +-
 tools/perf/builtin-top.c |  2 +-
 tools/perf/builtin-trace.c   |  2 +-
 tools/perf/lib/include/perf/mmap.h   |  2 +-
 tools/perf/lib/libperf.map   |  1 +-
 tools/perf/lib/mmap.c| 79 +++-
 tools/perf/tests/backward-ring-buffer.c  |  2 +-
 tools/perf/tests/bpf.c   |  2 +-
 tools/perf/tests/code-reading.c  |  2 +-
 tools/perf/tests/keep-tracking.c |  2 +-
 tools/perf/tests/mmap-basic.c|  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c  |  2 +-
 tools/perf/tests/perf-record.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/util/evlist.c |  2 +-
 tools/perf/util/mmap.c   | 77 +---
 tools/perf/util/mmap.h   |  2 +-
 tools/perf/util/python.c |  2 +-
 21 files changed, 98 insertions(+), 95 deletions(-)

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 c90d925..909ead0 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -121,7 +121,7 @@ int test__perf_time_to_tsc(struct test *test 
__maybe_unused, int subtest __maybe
if (perf_mmap__read_init(>core) < 0)
continue;
 
-   while ((event = perf_mmap__read_event(md)) != NULL) {
+   while ((event = perf_mmap__read_event(>core)) != NULL) {
struct perf_sample sample;
 
if (event->header.type != PERF_RECORD_COMM ||
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 4c087a8..858da89 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -764,7 +764,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat 
*kvm, int idx,
if (err < 0)
return (err == -EAGAIN) ? 0 : -1;
 
-   while ((event = perf_mmap__read_event(md)) != NULL) {
+   while ((event = perf_mmap__read_event(>core)) != NULL) {
err = perf_evlist__parse_sample_timestamp(evlist, event, 
);
if (err) {
perf_mmap__consume(>core);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 1a54069..d96f24c 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -873,7 +873,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, 
int idx)
if (perf_mmap__read_init(>core) < 0)
return;
 
-   while ((event = perf_mmap__read_event(md)) != NULL) {
+   while ((event = perf_mmap__read_event(>core)) != NULL) {
int ret;
 
ret = perf_evlist__parse_sample_timestamp(evlist, event, 
_timestamp);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 2311628..144d417 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3804,7 +3804,7 @@ again:
if (perf_mmap__read_init(>core) < 0)
continue;
 
-   while ((event = perf_mmap__read_event(md)) != NULL) {
+   while ((event = perf_mmap__read_event(>core)) != NULL) {
++trace->nr_events;
 
err = trace__deliver_event(trace, event);
diff --git a/tools/perf/lib/include/perf/mmap.h 
b/tools/perf/lib/include/perf/mmap.h
index 4f946e7..9508ad9 100644
--- a/tools/perf/lib/include/perf/mmap.h
+++ b/tools/perf/lib/include/perf/mmap.h
@@ -5,9 +5,11 @@
 #include 
 
 struct perf_mmap;
+union perf_event;
 
 LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
 LIBPERF_API int perf_mmap__read_init(struct perf_mmap *map);
 LIBPERF_API void perf_mmap__read_done(struct perf_mmap *map);
+LIBPERF_API union perf_event *perf_mmap__read_event(struct perf_mmap *map);
 
 #endif /* __LIBPERF_MMAP_H */
diff --git a/tools/perf/lib/libperf.map 

[tip: perf/core] libperf: Add perf_mmap__init() function

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 353120b48d4f61288e4745b0c8a191784b11c0f4
Gitweb:
https://git.kernel.org/tip/353120b48d4f61288e4745b0c8a191784b11c0f4
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:09 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 09:37:25 -03:00

libperf: Add perf_mmap__init() function

Add perf_mmap__init() function to initialize 'struct perf_mmap' objects.

Add it to a new mmap.c source file, that will carry all the mmap related
functions.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-2-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Build   |  1 +
 tools/perf/lib/include/internal/mmap.h |  2 ++
 tools/perf/lib/mmap.c  |  9 +
 tools/perf/util/evlist.c   |  5 ++---
 4 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 tools/perf/lib/mmap.c

diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index c31f1c1..2ef9a4e 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -3,6 +3,7 @@ libperf-y += cpumap.o
 libperf-y += threadmap.o
 libperf-y += evsel.o
 libperf-y += evlist.o
+libperf-y += mmap.o
 libperf-y += zalloc.o
 libperf-y += xyarray.o
 libperf-y += lib.o
diff --git a/tools/perf/lib/include/internal/mmap.h 
b/tools/perf/lib/include/internal/mmap.h
index ba1e519..e25890d 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -29,4 +29,6 @@ struct perf_mmap {
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
 };
 
+void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
new file mode 100644
index 000..3da6177
--- /dev/null
+++ b/tools/perf/lib/mmap.c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+
+void perf_mmap__init(struct perf_mmap *map, bool overwrite)
+{
+   map->fd = -1;
+   map->overwrite = overwrite;
+   refcount_set(>refcnt, 0);
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index e33b46a..6c8de08 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -629,8 +629,6 @@ static struct mmap *evlist__alloc_mmap(struct evlist 
*evlist,
return NULL;
 
for (i = 0; i < evlist->core.nr_mmaps; i++) {
-   map[i].core.fd = -1;
-   map[i].core.overwrite = overwrite;
/*
 * When the perf_mmap() call is made we grab one refcount, plus
 * one extra to let perf_mmap__consume() get the last
@@ -640,8 +638,9 @@ static struct mmap *evlist__alloc_mmap(struct evlist 
*evlist,
 * Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
 * thus does perf_mmap__get() on it.
 */
-   refcount_set([i].core.refcnt, 0);
+   perf_mmap__init([i].core, overwrite);
}
+
return map;
 }
 


[PATCH v2 5/5] perf report: Sort by sampled cycles percent per block for tui

2019-10-14 Thread Jin Yao
Previous patch has implemented a new sort option "total_cycles".
But there was only stdio mode supported.

This patch supports the tui mode and support '--percent-limit'.

For example,

 perf record -b ./div
 perf report -s total_cycles --percent-limit 1

 # Samples: 2753248 of event 'cycles'
 Sampled Cycles%  Sampled Cycles  Avg Cycles%  Avg Cycles   
   [Program Block Range] Shared Object
  26.04%2.8M0.40%  18   
  [div.c:42 -> div.c:39]   div
  15.17%1.2M0.16%   7   
  [random_r.c:357 -> random_r.c:380]  libc-2.27.so
   5.11%  402.0K0.04%   2   
  [div.c:27 -> div.c:28]   div
   4.87%  381.6K0.04%   2   
  [random.c:288 -> random.c:291]  libc-2.27.so
   4.53%  381.0K0.04%   2   
  [div.c:40 -> div.c:40]   div
   3.85%  300.9K0.02%   1   
  [div.c:22 -> div.c:25]   div
   3.08%  241.1K0.02%   1   
[rand.c:26 -> rand.c:27]  libc-2.27.so
   3.06%  240.0K0.02%   1   
  [random.c:291 -> random.c:291]  libc-2.27.so
   2.78%  215.7K0.02%   1   
  [random.c:298 -> random.c:298]  libc-2.27.so
   2.52%  198.3K0.02%   1   
  [random.c:293 -> random.c:293]  libc-2.27.so
   2.36%  184.8K0.02%   1   
[rand.c:28 -> rand.c:28]  libc-2.27.so
   2.33%  180.5K0.02%   1   
  [random.c:295 -> random.c:295]  libc-2.27.so
   2.28%  176.7K0.02%   1   
  [random.c:295 -> random.c:295]  libc-2.27.so
   2.20%  168.8K0.02%   1   
  [rand@plt+0 -> rand@plt+0]   div
   1.98%  158.2K0.02%   1   
  [random_r.c:388 -> random_r.c:388]  libc-2.27.so
   1.57%  123.3K0.02%   1   
  [div.c:42 -> div.c:44]   div
   1.44%  116.0K0.42%  19   
  [random_r.c:357 -> random_r.c:394]  libc-2.27.so

Signed-off-by: Jin Yao 
---
 tools/perf/builtin-report.c| 30 +---
 tools/perf/ui/browsers/hists.c | 62 +-
 tools/perf/ui/browsers/hists.h |  2 ++
 tools/perf/util/hist.h | 12 +++
 4 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 5dbde541b797..7dc74d794265 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -880,6 +880,27 @@ static int hists__fprintf_all_blocks(struct hists *hists, 
struct report *rep)
return 0;
 }
 
+static int perf_evlist__tui_block_hists_browse(struct evlist *evlist,
+  struct report *rep)
+{
+   struct block_hist *bh = >block_hist;
+   struct evsel *pos;
+   int ret;
+
+   evlist__for_each_entry(evlist, pos) {
+   struct hists *hists = evsel__hists(pos);
+
+   get_block_hists(hists, bh, rep);
+   symbol_conf.report_individual_block = true;
+   ret = block_hists_tui_browse(bh, pos, rep->min_percent);
+   hists__delete_entries(>block_hists);
+   if (ret != 0)
+   return ret;
+   }
+
+   return ret;
+}
+
 static int perf_evlist__tty_browse_hists(struct evlist *evlist,
 struct report *rep,
 const char *help)
@@ -988,6 +1009,11 @@ static int report__browse_hists(struct report *rep)
 
switch (use_browser) {
case 1:
+   if (rep->total_cycles) {
+   ret = perf_evlist__tui_block_hists_browse(evlist, rep);
+   break;
+   }
+
ret = perf_evlist__tui_browse_hists(evlist, help, NULL,
rep->min_percent,
>header.env,
@@ -1782,10 +1808,6 @@ int cmd_report(int argc, const char **argv)
if 

[PATCH v2 3/5] perf report: Sort by sampled cycles percent per block for stdio

2019-10-14 Thread Jin Yao
It would be useful to support sorting for all blocks by the
sampled cycles percent per block. This is useful to concentrate
on the globally hottest blocks.

This patch implements a new sort option "total_cycles" which sorts
all blocks by 'Sampled Cycles%'. The 'Sampled Cycles%' is the
percent that is,
block sampled cycles aggregation / total sampled cycles

Note that, this patch only supports "--stdio" mode.

For example,

perf record -b ./div
perf report -s total_cycles --stdio

 # To display the perf.data header info, please use --header/--header-only 
options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 2M of event 'cycles'
 # Event count (approx.): 2753248
 #
 # Sampled Cycles%  Sampled Cycles  Avg Cycles%  Avg Cycles 
 [Program Block Range] Shared Object
 # ...  ..  ...  ..  
.  

 #
26.04%2.8M0.40%  18 
[div.c:42 -> div.c:39]   div
15.17%1.2M0.16%   7 
[random_r.c:357 -> random_r.c:380]  libc-2.27.so
 5.11%  402.0K0.04%   2 
[div.c:27 -> div.c:28]   div
 4.87%  381.6K0.04%   2 
[random.c:288 -> random.c:291]  libc-2.27.so
 4.53%  381.0K0.04%   2 
[div.c:40 -> div.c:40]   div
 3.85%  300.9K0.02%   1 
[div.c:22 -> div.c:25]   div
 3.08%  241.1K0.02%   1 
  [rand.c:26 -> rand.c:27]  libc-2.27.so
 3.06%  240.0K0.02%   1 
[random.c:291 -> random.c:291]  libc-2.27.so
 2.78%  215.7K0.02%   1 
[random.c:298 -> random.c:298]  libc-2.27.so
 2.52%  198.3K0.02%   1 
[random.c:293 -> random.c:293]  libc-2.27.so
 2.36%  184.8K0.02%   1 
  [rand.c:28 -> rand.c:28]  libc-2.27.so
 2.33%  180.5K0.02%   1 
[random.c:295 -> random.c:295]  libc-2.27.so
 2.28%  176.7K0.02%   1 
[random.c:295 -> random.c:295]  libc-2.27.so
 2.20%  168.8K0.02%   1 
[rand@plt+0 -> rand@plt+0]   div
 1.98%  158.2K0.02%   1 
[random_r.c:388 -> random_r.c:388]  libc-2.27.so
 1.57%  123.3K0.02%   1 
[div.c:42 -> div.c:44]   div
 1.44%  116.0K0.42%  19 
[random_r.c:357 -> random_r.c:394]  libc-2.27.so
 0.25%  182.5K0.02%   1 
[random_r.c:388 -> random_r.c:391]  libc-2.27.so
 0.00%  481.07%  48 
[x86_pmu_enable+284 -> x86_pmu_enable+298] [kernel.kallsyms]
 0.00%  741.64%  74 
 [vm_mmap_pgoff+0 -> vm_mmap_pgoff+92] [kernel.kallsyms]
 0.00%  731.62%  73 
 [vm_mmap+0 -> vm_mmap+48] [kernel.kallsyms]
 0.00%  630.69%  31 
   [up_write+0 -> up_write+34] [kernel.kallsyms]
 0.00%  130.29%  13 
  [setup_arg_pages+396 -> setup_arg_pages+413] [kernel.kallsyms]
 0.00%   30.07%   3 
  [setup_arg_pages+418 -> setup_arg_pages+450] [kernel.kallsyms]
 0.00% 6166.84% 308
[security_mmap_file+0 -> security_mmap_file+72] [kernel.kallsyms]
 0.00%  230.51%  23   
[security_mmap_file+77 -> security_mmap_file+87] [kernel.kallsyms]
 0.00%   40.02%   1 
  [sched_clock+0 -> 

[PATCH v2 4/5] perf report: Support --percent-limit for total_cycles

2019-10-14 Thread Jin Yao
We have already supported the 'total_cycles' option in previous
patch. It's also useful to show entries only above a threshold
percent.

This patch enables '--percent-limit' for not showing entries
under that percent.

For example,

 perf report -s total_cycles --stdio --percent-limit 1

 # To display the perf.data header info, please use --header/--header-only 
options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 2M of event 'cycles'
 # Event count (approx.): 2753248
 #
 # Sampled Cycles%  Sampled Cycles  Avg Cycles%  Avg Cycles 
 [Program Block Range] Shared Object
 # ...  ..  ...  ..  
.  

 #
26.04%2.8M0.40%  18 
[div.c:42 -> div.c:39]   div
15.17%1.2M0.16%   7 
[random_r.c:357 -> random_r.c:380]  libc-2.27.so
 5.11%  402.0K0.04%   2 
[div.c:27 -> div.c:28]   div
 4.87%  381.6K0.04%   2 
[random.c:288 -> random.c:291]  libc-2.27.so
 4.53%  381.0K0.04%   2 
[div.c:40 -> div.c:40]   div
 3.85%  300.9K0.02%   1 
[div.c:22 -> div.c:25]   div
 3.08%  241.1K0.02%   1 
  [rand.c:26 -> rand.c:27]  libc-2.27.so
 3.06%  240.0K0.02%   1 
[random.c:291 -> random.c:291]  libc-2.27.so
 2.78%  215.7K0.02%   1 
[random.c:298 -> random.c:298]  libc-2.27.so
 2.52%  198.3K0.02%   1 
[random.c:293 -> random.c:293]  libc-2.27.so
 2.36%  184.8K0.02%   1 
  [rand.c:28 -> rand.c:28]  libc-2.27.so
 2.33%  180.5K0.02%   1 
[random.c:295 -> random.c:295]  libc-2.27.so
 2.28%  176.7K0.02%   1 
[random.c:295 -> random.c:295]  libc-2.27.so
 2.20%  168.8K0.02%   1 
[rand@plt+0 -> rand@plt+0]   div
 1.98%  158.2K0.02%   1 
[random_r.c:388 -> random_r.c:388]  libc-2.27.so
 1.57%  123.3K0.02%   1 
[div.c:42 -> div.c:44]   div
 1.44%  116.0K0.42%  19 
[random_r.c:357 -> random_r.c:394]  libc-2.27.so

It only shows the entries which 'Sampled Cycles%' > 1%.

Signed-off-by: Jin Yao 
---
 tools/perf/builtin-report.c |  2 +-
 tools/perf/ui/stdio/hist.c  |  7 ++-
 tools/perf/util/block.c | 10 ++
 tools/perf/util/block.h |  2 ++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f04a7b225a81..5dbde541b797 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -874,7 +874,7 @@ static int hists__fprintf_all_blocks(struct hists *hists, 
struct report *rep)
 
get_block_hists(hists, bh, rep);
symbol_conf.report_individual_block = true;
-   hists__fprintf(>block_hists, true, 0, 0, 0,
+   hists__fprintf(>block_hists, true, 0, 0, rep->min_percent,
   stdout, true);
hists__delete_entries(>block_hists);
return 0;
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 655ef7708cd0..d6991fc1d54e 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -15,6 +15,7 @@
 #include "../../util/srcline.h"
 #include "../../util/string2.h"
 #include "../../util/thread.h"
+#include "../../util/block.h"
 #include 
 #include 
 
@@ -856,7 +857,11 @@ size_t hists__fprintf(struct hists *hists, bool 
show_header, int max_rows,
if (h->filtered)
continue;
 
-   percent = hist_entry__get_percent_limit(h);
+   if (symbol_conf.report_individual_block)
+   percent = block_total_cycles_percent(h);
+   else
+   percent = 

[tip: perf/core] perf trace beauty: Add the glue for the autogenerated MSR arrays

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 646b3e2cfbf2d9207b4dbfaade7a28351aa7edeb
Gitweb:
https://git.kernel.org/tip/646b3e2cfbf2d9207b4dbfaade7a28351aa7edeb
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 07 Oct 2019 15:52:19 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf trace beauty: Add the glue for the autogenerated MSR arrays

We need to wrap those autogenerated string arrays with the
strarrays__scnprintf() formatter, do it.

Cc: Adrian Hunter 
Cc: Brendan Gregg 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-wqjz4kwi4a0ot6lsis3kc...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/trace/beauty/Build |  1 +-
 tools/perf/trace/beauty/beauty.h  |  3 ++-
 tools/perf/trace/beauty/tracepoints/Build |  1 +-
 tools/perf/trace/beauty/tracepoints/x86_msr.c | 34 ++-
 4 files changed, 39 insertions(+)
 create mode 100644 tools/perf/trace/beauty/tracepoints/Build
 create mode 100644 tools/perf/trace/beauty/tracepoints/x86_msr.c

diff --git a/tools/perf/trace/beauty/Build b/tools/perf/trace/beauty/Build
index afa75a7..433dc39 100644
--- a/tools/perf/trace/beauty/Build
+++ b/tools/perf/trace/beauty/Build
@@ -17,3 +17,4 @@ perf-y += sockaddr.o
 perf-y += socket.o
 perf-y += statx.o
 perf-y += sync_file_range.o
+perf-y += tracepoints/
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 5ad7542..aa3fac8 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -114,6 +114,9 @@ unsigned long syscall_arg__val(struct syscall_arg *arg, u8 
idx);
 size_t syscall_arg__scnprintf_strarray_flags(char *bf, size_t size, struct 
syscall_arg *arg);
 #define SCA_STRARRAY_FLAGS syscall_arg__scnprintf_strarray_flags
 
+size_t syscall_arg__scnprintf_x86_MSR(char *bf, size_t size, struct 
syscall_arg *arg);
+#define SCA_X86_MSR syscall_arg__scnprintf_x86_MSR
+
 size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size, struct 
syscall_arg *arg);
 #define SCA_STRARRAYS syscall_arg__scnprintf_strarrays
 
diff --git a/tools/perf/trace/beauty/tracepoints/Build 
b/tools/perf/trace/beauty/tracepoints/Build
new file mode 100644
index 000..625a676
--- /dev/null
+++ b/tools/perf/trace/beauty/tracepoints/Build
@@ -0,0 +1 @@
+perf-y += x86_msr.o
diff --git a/tools/perf/trace/beauty/tracepoints/x86_msr.c 
b/tools/perf/trace/beauty/tracepoints/x86_msr.c
new file mode 100644
index 000..5e9ef53
--- /dev/null
+++ b/tools/perf/trace/beauty/tracepoints/x86_msr.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * trace/beauty/x86_msr.c
+ *
+ *  Copyright (C) 2019, Red Hat Inc, Arnaldo Carvalho de Melo 
+ */
+
+#include "trace/beauty/beauty.h"
+
+#include "trace/beauty/generated/x86_arch_MSRs_array.c"
+
+static DEFINE_STRARRAY(x86_MSRs, "MSR_");
+static DEFINE_STRARRAY_OFFSET(x86_64_specific_MSRs, "MSR_", 
x86_64_specific_MSRs_offset);
+static DEFINE_STRARRAY_OFFSET(x86_AMD_V_KVM_MSRs, "MSR_", 
x86_AMD_V_KVM_MSRs_offset);
+
+static struct strarray *x86_MSRs_tables[] = {
+   __x86_MSRs,
+   __x86_64_specific_MSRs,
+   __x86_AMD_V_KVM_MSRs,
+};
+
+static DEFINE_STRARRAYS(x86_MSRs_tables);
+
+static size_t x86_MSR__scnprintf(unsigned long msr, char *bf, size_t size, 
bool show_prefix)
+{
+   return strarrays__scnprintf(__x86_MSRs_tables, bf, size, 
"%#x", show_prefix, msr);
+}
+
+size_t syscall_arg__scnprintf_x86_MSR(char *bf, size_t size, struct 
syscall_arg *arg)
+{
+   unsigned long flags = arg->val;
+
+   return x86_MSR__scnprintf(flags, bf, size, arg->show_string_prefix);
+}


[PATCH v2 1/5] perf util: Create new block.h/block.c for block related functions

2019-10-14 Thread Jin Yao
We have already implemented some block related functions. Now it's
time to do some cleanup, and move the functions and structures to
the new block.h/block.c.

Signed-off-by: Jin Yao 
---
 tools/perf/builtin-diff.c | 38 ++-
 tools/perf/util/Build |  1 +
 tools/perf/util/block.c   | 63 +++
 tools/perf/util/block.h   | 37 +++
 tools/perf/util/hist.c|  1 +
 tools/perf/util/symbol.c  | 22 --
 tools/perf/util/symbol.h  | 24 ---
 7 files changed, 104 insertions(+), 82 deletions(-)
 create mode 100644 tools/perf/util/block.c
 create mode 100644 tools/perf/util/block.h

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 5281629c27b1..05925b39718a 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -24,6 +24,7 @@
 #include "util/annotate.h"
 #include "util/map.h"
 #include "util/spark.h"
+#include "util/block.h"
 #include 
 #include 
 #include 
@@ -537,41 +538,6 @@ static void hists__baseline_only(struct hists *hists)
}
 }
 
-static int64_t block_cmp(struct perf_hpp_fmt *fmt __maybe_unused,
-struct hist_entry *left, struct hist_entry *right)
-{
-   struct block_info *bi_l = left->block_info;
-   struct block_info *bi_r = right->block_info;
-   int cmp;
-
-   if (!bi_l->sym || !bi_r->sym) {
-   if (!bi_l->sym && !bi_r->sym)
-   return 0;
-   else if (!bi_l->sym)
-   return -1;
-   else
-   return 1;
-   }
-
-   if (bi_l->sym == bi_r->sym) {
-   if (bi_l->start == bi_r->start) {
-   if (bi_l->end == bi_r->end)
-   return 0;
-   else
-   return (int64_t)(bi_r->end - bi_l->end);
-   } else
-   return (int64_t)(bi_r->start - bi_l->start);
-   } else {
-   cmp = strcmp(bi_l->sym->name, bi_r->sym->name);
-   return cmp;
-   }
-
-   if (bi_l->sym->start != bi_r->sym->start)
-   return (int64_t)(bi_r->sym->start - bi_l->sym->start);
-
-   return (int64_t)(bi_r->sym->end - bi_l->sym->end);
-}
-
 static int64_t block_cycles_diff_cmp(struct hist_entry *left,
 struct hist_entry *right)
 {
@@ -600,7 +566,7 @@ static void init_block_hist(struct block_hist *bh)
 
INIT_LIST_HEAD(>block_fmt.list);
INIT_LIST_HEAD(>block_fmt.sort_list);
-   bh->block_fmt.cmp = block_cmp;
+   bh->block_fmt.cmp = block_info__cmp;
bh->block_fmt.sort = block_sort;
perf_hpp_list__register_sort_field(>block_list,
   >block_fmt);
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 39814b1806a6..3121c0055950 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,4 +1,5 @@
 perf-y += annotate.o
+perf-y += block.o
 perf-y += block-range.o
 perf-y += build-id.o
 perf-y += cacheline.o
diff --git a/tools/perf/util/block.c b/tools/perf/util/block.c
new file mode 100644
index ..e5e6f941f040
--- /dev/null
+++ b/tools/perf/util/block.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include "block.h"
+#include "sort.h"
+
+struct block_info *block_info__get(struct block_info *bi)
+{
+   if (bi)
+   refcount_inc(>refcnt);
+   return bi;
+}
+
+void block_info__put(struct block_info *bi)
+{
+   if (bi && refcount_dec_and_test(>refcnt))
+   free(bi);
+}
+
+struct block_info *block_info__new(void)
+{
+   struct block_info *bi = zalloc(sizeof(*bi));
+
+   if (bi)
+   refcount_set(>refcnt, 1);
+   return bi;
+}
+
+int64_t block_info__cmp(struct perf_hpp_fmt *fmt __maybe_unused,
+   struct hist_entry *left, struct hist_entry *right)
+{
+   struct block_info *bi_l = left->block_info;
+   struct block_info *bi_r = right->block_info;
+   int cmp;
+
+   if (!bi_l->sym || !bi_r->sym) {
+   if (!bi_l->sym && !bi_r->sym)
+   return 0;
+   else if (!bi_l->sym)
+   return -1;
+   else
+   return 1;
+   }
+
+   if (bi_l->sym == bi_r->sym) {
+   if (bi_l->start == bi_r->start) {
+   if (bi_l->end == bi_r->end)
+   return 0;
+   else
+   return (int64_t)(bi_r->end - bi_l->end);
+   } else
+   return (int64_t)(bi_r->start - bi_l->start);
+   } else {
+   cmp = strcmp(bi_l->sym->name, bi_r->sym->name);
+   return cmp;
+   }
+
+   if (bi_l->sym->start != bi_r->sym->start)
+   return (int64_t)(bi_r->sym->start - bi_l->sym->start);
+

[tip: perf/core] perf evlist: Factor out asprintf routine to build a tracepoint pid filter

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 05cea4492c9dd28439cc73de1047ab3b26033736
Gitweb:
https://git.kernel.org/tip/05cea4492c9dd28439cc73de1047ab3b26033736
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 07 Oct 2019 16:43:03 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf evlist: Factor out asprintf routine to build a tracepoint pid filter

Will be used to append such lists to existing filters.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-798vlyqfqw938ehoe8eti...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index b4c43ac..c1b4608 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1053,6 +1053,9 @@ int perf_evlist__set_tp_filter(struct evlist *evlist, 
const char *filter)
struct evsel *evsel;
int err = 0;
 
+   if (filter == NULL)
+   return -1;
+
evlist__for_each_entry(evlist, evsel) {
if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT)
continue;
@@ -1065,16 +1068,15 @@ int perf_evlist__set_tp_filter(struct evlist *evlist, 
const char *filter)
return err;
 }
 
-int perf_evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t 
*pids)
+static char *asprintf__tp_filter_pids(size_t npids, pid_t *pids)
 {
char *filter;
-   int ret = -1;
size_t i;
 
for (i = 0; i < npids; ++i) {
if (i == 0) {
if (asprintf(, "common_pid != %d", pids[i]) < 0)
-   return -1;
+   return NULL;
} else {
char *tmp;
 
@@ -1086,9 +1088,18 @@ int perf_evlist__set_tp_filter_pids(struct evlist 
*evlist, size_t npids, pid_t *
}
}
 
-   ret = perf_evlist__set_tp_filter(evlist, filter);
+   return filter;
 out_free:
free(filter);
+   return NULL;
+}
+
+int perf_evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t 
*pids)
+{
+   char *filter = asprintf__tp_filter_pids(npids, pids);
+   int ret = perf_evlist__set_tp_filter(evlist, filter);
+
+   free(filter);
return ret;
 }
 


[tip: perf/core] perf evlist: Introduce append_tp_filter() method

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 53c92f73389d049d72b2e1d1cbc81c007241d422
Gitweb:
https://git.kernel.org/tip/53c92f73389d049d72b2e1d1cbc81c007241d422
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 07 Oct 2019 16:52:17 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf evlist: Introduce append_tp_filter() method

Will be used by 'perf trace' to support 'perf trace --filter', we need
to append to any pre-existing filter.

When parse_filter() gets invoked to process --filter, it'll set the
filter to that specified on the command line, later on, when we filter
out 'perf trace' own pid to avoid an event feedback loop, we need to
preserve the command line filter put in place by parse_filter().

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-h9rot08qmxlnfmte0holt...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 20 
 tools/perf/util/evlist.h |  2 ++
 2 files changed, 22 insertions(+)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c1b4608..1650d24 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1068,6 +1068,26 @@ int perf_evlist__set_tp_filter(struct evlist *evlist, 
const char *filter)
return err;
 }
 
+int perf_evlist__append_tp_filter(struct evlist *evlist, const char *filter)
+{
+   struct evsel *evsel;
+   int err = 0;
+
+   if (filter == NULL)
+   return -1;
+
+   evlist__for_each_entry(evlist, evsel) {
+   if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT)
+   continue;
+
+   err = perf_evsel__append_tp_filter(evsel, filter);
+   if (err)
+   break;
+   }
+
+   return err;
+}
+
 static char *asprintf__tp_filter_pids(size_t npids, pid_t *pids)
 {
char *filter;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 00eab94..c58fd19 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -140,6 +140,8 @@ int perf_evlist__set_tp_filter(struct evlist *evlist, const 
char *filter);
 int perf_evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
 int perf_evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t 
*pids);
 
+int perf_evlist__append_tp_filter(struct evlist *evlist, const char *filter);
+
 struct evsel *
 perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
 


[tip: perf/core] perf trace: Associate the "msr" tracepoint arg name with x86_MSR__scnprintf()

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: c330ef2847eeedfa9d06f03836dfd4fc6727e855
Gitweb:
https://git.kernel.org/tip/c330ef2847eeedfa9d06f03836dfd4fc6727e855
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 07 Oct 2019 15:54:51 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf trace: Associate the "msr" tracepoint arg name with x86_MSR__scnprintf()

So that we can go from:

  # perf trace -e msr:write_msr --max-stack=16 sleep 1
   0.000 sleep/6740 msr:write_msr(msr: 3221225728, val: 139636317451648)
 do_trace_write_msr ([kernel.kallsyms])
 do_trace_write_msr ([kernel.kallsyms])
 do_arch_prctl_64 ([kernel.kallsyms])
 __x64_sys_arch_prctl 
([kernel.kallsyms])
 do_syscall_64 ([kernel.kallsyms])
 entry_SYSCALL_64 ([kernel.kallsyms])
 init_tls (/usr/lib64/ld-2.29.so)
 dl_main (/usr/lib64/ld-2.29.so)
 _dl_sysdep_start 
(/usr/lib64/ld-2.29.so)
 _dl_start (/usr/lib64/ld-2.29.so)
  #

To:

  # perf trace -e msr:write_msr --max-stack=16 sleep 1
 0.000 sleep/8519 msr:write_msr(msr: FS_BASE, val: 139878031705472)
   do_trace_write_msr ([kernel.kallsyms])
   do_trace_write_msr ([kernel.kallsyms])
   do_arch_prctl_64 ([kernel.kallsyms])
   __x64_sys_arch_prctl ([kernel.kallsyms])
   do_syscall_64 ([kernel.kallsyms])
   entry_SYSCALL_64 ([kernel.kallsyms])
   init_tls (/usr/lib64/ld-2.29.so)
   dl_main (/usr/lib64/ld-2.29.so)
   _dl_sysdep_start (/usr/lib64/ld-2.29.so)
   _dl_start (/usr/lib64/ld-2.29.so)
  #

This, in reverse, will allow for symbolic system call/tracepoint
filtering.

Cc: Adrian Hunter 
Cc: Brendan Gregg 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-q1q4unmqja5ex7dy0kb5c...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index d52972c..e9f132a 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1480,6 +1480,7 @@ static int syscall__alloc_arg_fmts(struct syscall *sc, 
int nr_args)
 }
 
 static struct syscall_arg_fmt syscall_arg_fmts__by_name[] = {
+   { .name = "msr", .scnprintf = SCA_X86_MSR, }
 };
 
 static int syscall_arg_fmt__cmp(const void *name, const void *fmtp)


[PATCH v2 0/5] perf report: Support sorting all blocks by cycles

2019-10-14 Thread Jin Yao
It would be useful to support sorting for all blocks by the
sampled cycles percent per block. This is useful to concentrate
on the globally hottest blocks.

This patch series implements a new sort option "total_cycles" which
sorts all blocks by 'Sampled Cycles%'. The 'Sampled Cycles%' is
block sampled cycles aggregation / total sampled cycles

For example,

perf record -b ./div
perf report -s total_cycles --stdio

 # To display the perf.data header info, please use --header/--header-only 
options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 2M of event 'cycles'
 # Event count (approx.): 2753248
 #
 # Sampled Cycles%  Sampled Cycles  Avg Cycles%  Avg Cycles 
 [Program Block Range] Shared Object
 # ...  ..  ...  ..  
.  

 #
26.04%2.8M0.40%  18 
[div.c:42 -> div.c:39]   div
15.17%1.2M0.16%   7 
[random_r.c:357 -> random_r.c:380]  libc-2.27.so
 5.11%  402.0K0.04%   2 
[div.c:27 -> div.c:28]   div
 4.87%  381.6K0.04%   2 
[random.c:288 -> random.c:291]  libc-2.27.so
 4.53%  381.0K0.04%   2 
[div.c:40 -> div.c:40]   div
 3.85%  300.9K0.02%   1 
[div.c:22 -> div.c:25]   div
 3.08%  241.1K0.02%   1 
  [rand.c:26 -> rand.c:27]  libc-2.27.so
 3.06%  240.0K0.02%   1 
[random.c:291 -> random.c:291]  libc-2.27.so
 2.78%  215.7K0.02%   1 
[random.c:298 -> random.c:298]  libc-2.27.so
 2.52%  198.3K0.02%   1 
[random.c:293 -> random.c:293]  libc-2.27.so
 2.36%  184.8K0.02%   1 
  [rand.c:28 -> rand.c:28]  libc-2.27.so
 2.33%  180.5K0.02%   1 
[random.c:295 -> random.c:295]  libc-2.27.so
 2.28%  176.7K0.02%   1 
[random.c:295 -> random.c:295]  libc-2.27.so
 2.20%  168.8K0.02%   1 
[rand@plt+0 -> rand@plt+0]   div
 1.98%  158.2K0.02%   1 
[random_r.c:388 -> random_r.c:388]  libc-2.27.so
 1.57%  123.3K0.02%   1 
[div.c:42 -> div.c:44]   div
 1.44%  116.0K0.42%  19 
[random_r.c:357 -> random_r.c:394]  libc-2.27.so
 ..

This patch series supports both stdio and tui. And also with the supporting
of --percent-limit.

 v2:
 ---
 Rebase to perf/core branch

Jin Yao (5):
  perf util: Create new block.h/block.c for block related functions
  perf util: Count the total cycles of all samples
  perf report: Sort by sampled cycles percent per block for stdio
  perf report: Support --percent-limit for total_cycles
  perf report: Sort by sampled cycles percent per block for tui

 tools/perf/Documentation/perf-report.txt |  10 +
 tools/perf/builtin-annotate.c|   2 +-
 tools/perf/builtin-diff.c|  41 +--
 tools/perf/builtin-report.c  | 445 ++-
 tools/perf/builtin-top.c |   3 +-
 tools/perf/ui/browsers/hists.c   |  62 +++-
 tools/perf/ui/browsers/hists.h   |   2 +
 tools/perf/ui/stdio/hist.c   |  29 +-
 tools/perf/util/Build|   1 +
 tools/perf/util/block.c  |  73 
 tools/perf/util/block.h  |  40 ++
 tools/perf/util/hist.c   |  11 +-
 tools/perf/util/hist.h   |  15 +-
 tools/perf/util/sort.c   |   5 +
 tools/perf/util/sort.h   |   1 +
 tools/perf/util/symbol.c |  22 --
 tools/perf/util/symbol.h |  24 --
 tools/perf/util/symbol_conf.h|   1 +
 18 files changed, 694 insertions(+), 93 deletions(-)
 create mode 100644 tools/perf/util/block.c
 create mode 100644 

[PATCH v2 2/5] perf util: Count the total cycles of all samples

2019-10-14 Thread Jin Yao
We can get the per sample cycles by hist__account_cycles(). It's also
useful to know the total cycles of all samples in order to get the
cycles coverage for a single program block in further. For example,

coverage = per block sampled cycles / total sampled cycles

This patch creates a new argument 'total_cycles' in hist__account_cycles(),
which will be added with the cycles of each sample.

Signed-off-by: Jin Yao 
---
 tools/perf/builtin-annotate.c | 2 +-
 tools/perf/builtin-diff.c | 3 ++-
 tools/perf/builtin-report.c   | 2 +-
 tools/perf/builtin-top.c  | 3 ++-
 tools/perf/util/hist.c| 6 +-
 tools/perf/util/hist.h| 3 ++-
 6 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 8db8fc9bddef..6ab0cc45b287 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -201,7 +201,7 @@ static int process_branch_callback(struct evsel *evsel,
if (a.map != NULL)
a.map->dso->hit = 1;
 
-   hist__account_cycles(sample->branch_stack, al, sample, false);
+   hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
 
ret = hist_entry_iter__add(, , PERF_MAX_STACK_DEPTH, ann);
return ret;
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 05925b39718a..7487e113454f 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -428,7 +428,8 @@ static int diff__process_sample_event(struct perf_tool 
*tool,
goto out_put;
}
 
-   hist__account_cycles(sample->branch_stack, , sample, false);
+   hist__account_cycles(sample->branch_stack, , sample, false,
+NULL);
}
 
/*
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 7accaf8ef689..cdb436d6e11f 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -292,7 +292,7 @@ static int process_sample_event(struct perf_tool *tool,
 
if (ui__has_annotation() || rep->symbol_ipc) {
hist__account_cycles(sample->branch_stack, , sample,
-rep->nonany_branch_mode);
+rep->nonany_branch_mode, NULL);
}
 
ret = hist_entry_iter__add(, , rep->max_stack, rep);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index d96f24c8770d..14c52e4d47f6 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -725,7 +725,8 @@ static int hist_iter__top_callback(struct hist_entry_iter 
*iter,
perf_top__record_precise_ip(top, he, iter->sample, evsel, 
al->addr);
 
hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
-!(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));
+!(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY),
+NULL);
return 0;
 }
 
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 26ee45a3e5d0..af65ce950ba2 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -2570,7 +2570,8 @@ int hists__unlink(struct hists *hists)
 }
 
 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
- struct perf_sample *sample, bool nonany_branch_mode)
+ struct perf_sample *sample, bool nonany_branch_mode,
+ u64 *total_cycles)
 {
struct branch_info *bi;
 
@@ -2597,6 +2598,9 @@ void hist__account_cycles(struct branch_stack *bs, struct 
addr_location *al,
nonany_branch_mode ? NULL : prev,
bi[i].flags.cycles);
prev = [i].to;
+
+   if (total_cycles)
+   *total_cycles += bi[i].flags.cycles;
}
free(bi);
}
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 6a186b668303..4d87c7b4c1b2 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -527,7 +527,8 @@ unsigned int hists__sort_list_width(struct hists *hists);
 unsigned int hists__overhead_width(struct hists *hists);
 
 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
- struct perf_sample *sample, bool nonany_branch_mode);
+ struct perf_sample *sample, bool nonany_branch_mode,
+ u64 *total_cycles);
 
 struct option;
 int parse_filter_percentage(const struct option *opt, const char *arg, int 
unset);
-- 
2.17.1



[tip: perf/core] libperf: Adopt perf_mmap__put() function from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 80e53d1148231d7d4fdc4cd89e5393616b33bf82
Gitweb:
https://git.kernel.org/tip/80e53d1148231d7d4fdc4cd89e5393616b33bf82
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:15 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 10:09:25 -03:00

libperf: Adopt perf_mmap__put() function from tools/perf

Move perf_mmap__put() from tools/perf to libperf.

Once perf_mmap__put() is moved, we need a way to call application
related unmap code (AIO and aux related code for eprf), when the map
goes away.

Add the perf_mmap::unmap callback to do that.

The unmap path from perf is:

  perf_mmap__put   (libperf)
perf_mmap__munmap  (libperf)
  map->unmap_cb -> perf_mmap__unmap_cb (perf)
mmap__munmap   (perf)

Committer notes:

Add missing linux/kernel.h to tools/perf/lib/mmap.c to get the BUG_ON
definition.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-8-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c|  4 +--
 tools/perf/lib/include/internal/mmap.h | 31 +++--
 tools/perf/lib/mmap.c  | 15 +++-
 tools/perf/util/evlist.c   | 17 +-
 tools/perf/util/mmap.c | 11 +-
 tools/perf/util/mmap.h |  2 +--
 6 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 025a12b..2fb83aa 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -197,7 +197,7 @@ static int record__aio_complete(struct mmap *md, struct 
aiocb *cblock)
 * every aio write request started in record__aio_push() so
 * decrement it because the request is now complete.
 */
-   perf_mmap__put(md);
+   perf_mmap__put(>core);
rc = 1;
} else {
/*
@@ -332,7 +332,7 @@ static int record__aio_push(struct record *rec, struct mmap 
*map, off_t *off)
 * map->refcount is decremented in record__aio_complete() after
 * aio write operation finishes successfully.
 */
-   perf_mmap__put(map);
+   perf_mmap__put(>core);
}
 
return ret;
diff --git a/tools/perf/lib/include/internal/mmap.h 
b/tools/perf/lib/include/internal/mmap.h
index 5c2ca9a..bf9cc7d 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -10,23 +10,28 @@
 /* perf sample has 16 bits size limit */
 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
 
+struct perf_mmap;
+
+typedef void (*libperf_unmap_cb_t)(struct perf_mmap *map);
+
 /**
  * struct perf_mmap - perf's ring buffer mmap details
  *
  * @refcnt - e.g. code using PERF_EVENT_IOC_SET_OUTPUT to share this
  */
 struct perf_mmap {
-   void*base;
-   int  mask;
-   int  fd;
-   int  cpu;
-   refcount_t   refcnt;
-   u64  prev;
-   u64  start;
-   u64  end;
-   bool overwrite;
-   u64  flush;
-   char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
+   void*base;
+   int  mask;
+   int  fd;
+   int  cpu;
+   refcount_t   refcnt;
+   u64  prev;
+   u64  start;
+   u64  end;
+   bool overwrite;
+   u64  flush;
+   libperf_unmap_cb_t   unmap_cb;
+   char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
 };
 
 struct perf_mmap_param {
@@ -36,10 +41,12 @@ struct perf_mmap_param {
 
 size_t perf_mmap__mmap_len(struct perf_mmap *map);
 
-void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+void perf_mmap__init(struct perf_mmap *map, bool overwrite,
+libperf_unmap_cb_t unmap_cb);
 int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, int cpu);
 void perf_mmap__munmap(struct perf_mmap *map);
 void perf_mmap__get(struct perf_mmap *map);
+void perf_mmap__put(struct perf_mmap *map);
 
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 6eb228d..89c1e0e 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -2,11 +2,14 @@
 #include 
 #include 
 #include 
+#include 
 
-void perf_mmap__init(struct perf_mmap *map, bool overwrite)
+void perf_mmap__init(struct perf_mmap *map, bool overwrite,
+

[tip: perf/core] perf trace: Enclose all events argument lists with ()

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 311baaf93c4b9e6a339722006d1a7c33e4283c0c
Gitweb:
https://git.kernel.org/tip/311baaf93c4b9e6a339722006d1a7c33e4283c0c
Author:Arnaldo Carvalho de Melo 
AuthorDate:Fri, 04 Oct 2019 15:01:30 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf trace: Enclose all events argument lists with ()

So that they look a bit like normal strace-like syscall enter+exit
lines.

They will look even more when we switch from using libtraceevent's
tep_print_event() routine in favour of using all the perf beautifiers
used by the strace-like syscall enter+exit lines.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-y4fcej6v6u1m644nbxd2r...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index b3fb208..297aeaa 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2450,7 +2450,7 @@ static int trace__event_handler(struct trace *trace, 
struct evsel *evsel,
 */
}
 
-   fprintf(trace->output, "%s:", evsel->name);
+   fprintf(trace->output, "%s(", evsel->name);
 
if (perf_evsel__is_bpf_output(evsel)) {
bpf_output__fprintf(trace, sample);
@@ -2470,7 +2470,7 @@ static int trace__event_handler(struct trace *trace, 
struct evsel *evsel,
}
 
 newline:
-   fprintf(trace->output, "\n");
+   fprintf(trace->output, ")\n");
 
if (callchain_ret > 0)
trace__fprintf_callchain(trace, sample);


[tip: perf/core] libperf: Adopt perf_mmap__mmap() function from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 32c261c070c222858148c2171698d2954242ddd9
Gitweb:
https://git.kernel.org/tip/32c261c070c222858148c2171698d2954242ddd9
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:12 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 09:42:59 -03:00

libperf: Adopt perf_mmap__mmap() function from tools/perf

Move perf_mmap__mmap() from tools/perf to libperf, it will be used in
the following patches. And rename the existing perf's function to
mmap__mmap().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-5-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/internal/mmap.h |  2 ++
 tools/perf/lib/mmap.c  | 18 ++
 tools/perf/util/evlist.c   |  2 +-
 tools/perf/util/mmap.c | 12 +++-
 tools/perf/util/mmap.h |  2 +-
 5 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/tools/perf/lib/include/internal/mmap.h 
b/tools/perf/lib/include/internal/mmap.h
index e7a6726..7067b70 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -37,5 +37,7 @@ struct perf_mmap_param {
 size_t perf_mmap__mmap_len(struct perf_mmap *map);
 
 void perf_mmap__init(struct perf_mmap *map, bool overwrite);
+int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
+   int fd, int cpu);
 
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index cc4284d..b216a7d 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#include 
 #include 
 #include 
 
@@ -13,3 +14,20 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map)
 {
return map->mask + 1 + page_size;
 }
+
+int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
+   int fd, int cpu)
+{
+   map->prev = 0;
+   map->mask = mp->mask;
+   map->base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
+MAP_SHARED, fd, 0);
+   if (map->base == MAP_FAILED) {
+   map->base = NULL;
+   return -1;
+   }
+
+   map->fd  = fd;
+   map->cpu = cpu;
+   return 0;
+}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 3a19a7c..f9781de 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -695,7 +695,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, 
int idx,
if (*output == -1) {
*output = fd;
 
-   if (perf_mmap__mmap([idx], mp, *output, 
evlist_cpu) < 0)
+   if (mmap__mmap([idx], mp, *output, evlist_cpu) < 0)
return -1;
} else {
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index a8e81c4..acef6e3 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -353,7 +353,7 @@ static void perf_mmap__setup_affinity_mask(struct mmap 
*map, struct mmap_params 
CPU_SET(map->core.cpu, >affinity_mask);
 }
 
-int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
+int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu)
 {
/*
 * The last one will be done at perf_mmap__consume(), so that we
@@ -369,18 +369,12 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params 
*mp, int fd, int cpu)
 * perf_evlist__filter_pollfd().
 */
refcount_set(>core.refcnt, 2);
-   map->core.prev = 0;
-   map->core.mask = mp->core.mask;
-   map->core.base = mmap(NULL, mmap__mmap_len(map), mp->core.prot,
-MAP_SHARED, fd, 0);
-   if (map->core.base == MAP_FAILED) {
+
+   if (perf_mmap__mmap(>core, >core, fd, cpu)) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
  errno);
-   map->core.base = NULL;
return -1;
}
-   map->core.fd = fd;
-   map->core.cpu = cpu;
 
perf_mmap__setup_affinity_mask(map, mp);
 
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 2b97dc6..a60e6ea 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -42,7 +42,7 @@ struct mmap_params {
struct auxtrace_mmap_params auxtrace_mp;
 };
 
-int perf_mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
+int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
 void perf_mmap__munmap(struct mmap *map);
 
 void perf_mmap__get(struct mmap *map);


[tip: perf/core] libperf: Adopt perf_mmap__read_done() from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 32fdc2ca7e2ae8ae5d0ff660ca7783acd8ee6396
Gitweb:
https://git.kernel.org/tip/32fdc2ca7e2ae8ae5d0ff660ca7783acd8ee6396
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:19 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 11:45:32 -03:00

libperf: Adopt perf_mmap__read_done() from tools/perf

Move perf_mmap__read_init() from tools/perf to libperf and export it in
the perf/mmap.h header.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-12-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |  2 +-
 tools/perf/builtin-kvm.c |  2 +-
 tools/perf/builtin-top.c |  2 +-
 tools/perf/builtin-trace.c   |  2 +-
 tools/perf/lib/include/perf/mmap.h   |  1 +
 tools/perf/lib/libperf.map   |  1 +
 tools/perf/lib/mmap.c| 17 +
 tools/perf/tests/backward-ring-buffer.c  |  2 +-
 tools/perf/tests/bpf.c   |  2 +-
 tools/perf/tests/code-reading.c  |  2 +-
 tools/perf/tests/keep-tracking.c |  2 +-
 tools/perf/tests/mmap-basic.c|  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c  |  2 +-
 tools/perf/tests/perf-record.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/util/evlist.c |  2 +-
 tools/perf/util/mmap.c   | 17 -
 tools/perf/util/mmap.h   |  1 -
 20 files changed, 34 insertions(+), 33 deletions(-)

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 6a0c3ff..c90d925 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -142,7 +142,7 @@ int test__perf_time_to_tsc(struct test *test 
__maybe_unused, int subtest __maybe
 next_event:
perf_mmap__consume(>core);
}
-   perf_mmap__read_done(md);
+   perf_mmap__read_done(>core);
}
 
if (!comm1_time || !comm2_time)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index b6a8078..4c087a8 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -794,7 +794,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat 
*kvm, int idx,
break;
}
 
-   perf_mmap__read_done(md);
+   perf_mmap__read_done(>core);
return n;
 }
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 4a4bb7b..1a54069 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -894,7 +894,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, 
int idx)
}
}
 
-   perf_mmap__read_done(md);
+   perf_mmap__read_done(>core);
 }
 
 static void perf_top__mmap_read(struct perf_top *top)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index cd69d68..2311628 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3821,7 +3821,7 @@ again:
draining = true;
}
}
-   perf_mmap__read_done(md);
+   perf_mmap__read_done(>core);
}
 
if (trace->nr_events == before) {
diff --git a/tools/perf/lib/include/perf/mmap.h 
b/tools/perf/lib/include/perf/mmap.h
index 646e905..4f946e7 100644
--- a/tools/perf/lib/include/perf/mmap.h
+++ b/tools/perf/lib/include/perf/mmap.h
@@ -8,5 +8,6 @@ struct perf_mmap;
 
 LIBPERF_API void perf_mmap__consume(struct perf_mmap *map);
 LIBPERF_API int perf_mmap__read_init(struct perf_mmap *map);
+LIBPERF_API void perf_mmap__read_done(struct perf_mmap *map);
 
 #endif /* __LIBPERF_MMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index bc3fbb2..7e3ea2e 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -42,6 +42,7 @@ LIBPERF_0.0.1 {
perf_evlist__poll;
perf_mmap__consume;
perf_mmap__read_init;
+   perf_mmap__read_done;
local:
*;
 };
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index fdbc6c5..97297cb 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -175,3 +175,20 @@ int perf_mmap__read_init(struct perf_mmap *map)
 
return __perf_mmap__read_init(map);
 }
+
+/*
+ * Mandatory for overwrite mode
+ * The direction of overwrite mode is backward.
+ * The last perf_mmap__read() will set tail to map->core.prev.
+ * Need to correct the map->core.prev to head 

[tip: perf/core] perf trace beauty: Add a x86 MSR cmd id->str table generator

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 693d345818e106318710ac150ae252b73765d0fa
Gitweb:
https://git.kernel.org/tip/693d345818e106318710ac150ae252b73765d0fa
Author:Arnaldo Carvalho de Melo 
AuthorDate:Thu, 26 Sep 2019 15:28:02 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf trace beauty: Add a x86 MSR cmd id->str table generator

Without parameters it'll parse tools/arch/x86/include/asm/msr-index.h
and output a table usable by tools, that will be wired up later to a
libtraceevent plugin registered from perf's glue code:

  $ tools/perf/trace/beauty/tracepoints/x86_msr.sh
  static const char *x86_MSRs[] = {
 
[0x0034] = "SMI_COUNT",
[0x003a] = "IA32_FEATURE_CONTROL",
[0x003b] = "IA32_TSC_ADJUST",
[0x0040] = "LBR_CORE_FROM",
[0x0048] = "IA32_SPEC_CTRL",
[0x0049] = "IA32_PRED_CMD",
 
[0x010b] = "IA32_FLUSH_CMD",
[0x010F] = "TSX_FORCE_ABORT",
 
[0x0198] = "IA32_PERF_STATUS",
[0x0199] = "IA32_PERF_CTL",
  
[0x0da0] = "IA32_XSS",
[0x0dc0] = "LBR_INFO_0",
[0x0ffc] = "IA32_BNDCFGS_RSVD",
  };

  #define x86_64_specific_MSRs_offset 0xc080
  static const char *x86_64_specific_MSRs[] = {
[0xc080 - x86_64_specific_MSRs_offset] = "EFER",
[0xc081 - x86_64_specific_MSRs_offset] = "STAR",
[0xc082 - x86_64_specific_MSRs_offset] = "LSTAR",
[0xc083 - x86_64_specific_MSRs_offset] = "CSTAR",
[0xc084 - x86_64_specific_MSRs_offset] = "SYSCALL_MASK",
  
[0xc103 - x86_64_specific_MSRs_offset] = "TSC_AUX",
[0xc104 - x86_64_specific_MSRs_offset] = "AMD64_TSC_RATIO",
  };

  #define x86_AMD_V_KVM_MSRs_offset 0xc001
  static const char *x86_AMD_V_KVM_MSRs[] = {
[0xc001 - x86_AMD_V_KVM_MSRs_offset] = "K7_EVNTSEL0",
  
[0xc0010114 - x86_AMD_V_KVM_MSRs_offset] = "VM_CR",
[0xc0010115 - x86_AMD_V_KVM_MSRs_offset] = "VM_IGNNE",
[0xc0010117 - x86_AMD_V_KVM_MSRs_offset] = "VM_HSAVE_PA",
  
[0xc0010240 - x86_AMD_V_KVM_MSRs_offset] = "F15H_NB_PERF_CTL",
[0xc0010241 - x86_AMD_V_KVM_MSRs_offset] = "F15H_NB_PERF_CTR",
[0xc0010280 - x86_AMD_V_KVM_MSRs_offset] = "F15H_PTSC",
  };

Then these will in turn be hooked up in a follow up patch to be used by
strarrays__scnprintf().

Cc: Adrian Hunter 
Cc: Brendan Gregg 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-ja080xawx08kedez855us...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/trace/beauty/tracepoints/x86_msr.sh | 40 +-
 1 file changed, 40 insertions(+)
 create mode 100755 tools/perf/trace/beauty/tracepoints/x86_msr.sh

diff --git a/tools/perf/trace/beauty/tracepoints/x86_msr.sh 
b/tools/perf/trace/beauty/tracepoints/x86_msr.sh
new file mode 100755
index 000..831c02c
--- /dev/null
+++ b/tools/perf/trace/beauty/tracepoints/x86_msr.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# SPDX-License-Identifier: LGPL-2.1
+
+if [ $# -ne 1 ] ; then
+   arch_x86_header_dir=tools/arch/x86/include/asm/
+else
+   arch_x86_header_dir=$1
+fi
+
+x86_msr_index=${arch_x86_header_dir}/msr-index.h
+
+# Support all later, with some hash table, for now chop off
+# Just the ones starting with 0x0 so as to have a simple
+# array.
+
+printf "static const char *x86_MSRs[] = {\n"
+regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x0[[:xdigit:]]+)[[:space:]]*.*'
+egrep $regex ${x86_msr_index} | egrep -v 
'MSR_(ATOM|P[46]|AMD64|IA32_TSCDEADLINE|IDT_FCR4)' | \
+   sed -r "s/$regex/\2 \1/g" | sort -n | \
+   xargs printf "\t[%s] = \"%s\",\n"
+printf "};\n\n"
+
+# Remove MSR_K6_WHCR, clashes with MSR_LSTAR
+regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0xc[[:xdigit:]]+)[[:space:]]*.*'
+printf "#define x86_64_specific_MSRs_offset "
+egrep $regex ${x86_msr_index} | sed -r "s/$regex/\2/g" | sort -n | head -1
+printf "static const char *x86_64_specific_MSRs[] = {\n"
+egrep $regex ${x86_msr_index} | \
+   sed -r "s/$regex/\2 \1/g" | egrep -vw 'K6_WHCR' | sort -n | \
+   xargs printf "\t[%s - x86_64_specific_MSRs_offset] = \"%s\",\n"
+printf "};\n\n"
+
+regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MSR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0xc0010[[:xdigit:]]+)[[:space:]]*.*'
+printf "#define x86_AMD_V_KVM_MSRs_offset "
+egrep $regex ${x86_msr_index} | sed -r "s/$regex/\2/g" | sort -n | head -1
+printf "static const char *x86_AMD_V_KVM_MSRs[] = {\n"
+egrep $regex ${x86_msr_index} | \
+   sed -r "s/$regex/\2 \1/g" | sort -n | \
+   xargs printf "\t[%s - x86_AMD_V_KVM_MSRs_offset] = \"%s\",\n"
+printf "};\n"


[tip: perf/core] perf trace: Move some scnprintf methods from syscall to syscall_arg_fmt

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 3e0c9b2cfaed25599a0a5cbd40e37871bdb10523
Gitweb:
https://git.kernel.org/tip/3e0c9b2cfaed25599a0a5cbd40e37871bdb10523
Author:Arnaldo Carvalho de Melo 
AuthorDate:Fri, 04 Oct 2019 11:30:41 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf trace: Move some scnprintf methods from syscall to syscall_arg_fmt

Since all they operate on is on a syscall_arg_fmt instance, so move them
to allow use it from the upcoming tracepoint fprintf routine.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-ynttrs1l75f0x9tk67spd...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index aa70602..82d39ef 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1715,22 +1715,22 @@ static size_t syscall__scnprintf_name(struct syscall 
*sc, char *bf, size_t size,
  * as mount 'flags' argument that needs ignoring some magic flag, see comment
  * in tools/perf/trace/beauty/mount_flags.c
  */
-static unsigned long syscall__mask_val(struct syscall *sc, struct syscall_arg 
*arg, unsigned long val)
+static unsigned long syscall_arg_fmt__mask_val(struct syscall_arg_fmt *fmt, 
struct syscall_arg *arg, unsigned long val)
 {
-   if (sc->arg_fmt && sc->arg_fmt[arg->idx].mask_val)
-   return sc->arg_fmt[arg->idx].mask_val(arg, val);
+   if (fmt && fmt->mask_val)
+   return fmt->mask_val(arg, val);
 
return val;
 }
 
-static size_t syscall__scnprintf_val(struct syscall *sc, char *bf, size_t size,
-struct syscall_arg *arg, unsigned long val)
+static size_t syscall_arg_fmt__scnprintf_val(struct syscall_arg_fmt *fmt, char 
*bf, size_t size,
+struct syscall_arg *arg, unsigned 
long val)
 {
-   if (sc->arg_fmt && sc->arg_fmt[arg->idx].scnprintf) {
+   if (fmt && fmt->scnprintf) {
arg->val = val;
-   if (sc->arg_fmt[arg->idx].parm)
-   arg->parm = sc->arg_fmt[arg->idx].parm;
-   return sc->arg_fmt[arg->idx].scnprintf(bf, size, arg);
+   if (fmt->parm)
+   arg->parm = fmt->parm;
+   return fmt->scnprintf(bf, size, arg);
}
return scnprintf(bf, size, "%ld", val);
 }
@@ -1776,7 +1776,7 @@ static size_t syscall__scnprintf_args(struct syscall *sc, 
char *bf, size_t size,
 * Some syscall args need some mask, most don't and
 * return val untouched.
 */
-   val = syscall__mask_val(sc, , val);
+   val = syscall_arg_fmt__mask_val(>arg_fmt[arg.idx], 
, val);
 
/*
 * Suppress this argument if its value is zero and
@@ -1797,7 +1797,8 @@ static size_t syscall__scnprintf_args(struct syscall *sc, 
char *bf, size_t size,
if (trace->show_arg_names)
printed += scnprintf(bf + printed, size - 
printed, "%s: ", field->name);
 
-   printed += syscall__scnprintf_val(sc, bf + printed, 
size - printed, , val);
+   printed += 
syscall_arg_fmt__scnprintf_val(>arg_fmt[arg.idx],
+ bf + printed, 
size - printed, , val);
}
} else if (IS_ERR(sc->tp_format)) {
/*
@@ -1812,7 +1813,7 @@ static size_t syscall__scnprintf_args(struct syscall *sc, 
char *bf, size_t size,
if (printed)
printed += scnprintf(bf + printed, size - 
printed, ", ");
printed += syscall__scnprintf_name(sc, bf + printed, 
size - printed, );
-   printed += syscall__scnprintf_val(sc, bf + printed, 
size - printed, , val);
+   printed += 
syscall_arg_fmt__scnprintf_val(>arg_fmt[arg.idx], bf + printed, size - 
printed, , val);
 next_arg:
++arg.idx;
bit <<= 1;


[tip: perf/core] perf beauty: Introduce strtoul() for x86 MSRs

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 728db198868c7b46db5e65717d4518aeb6523ccc
Gitweb:
https://git.kernel.org/tip/728db198868c7b46db5e65717d4518aeb6523ccc
Author:Arnaldo Carvalho de Melo 
AuthorDate:Wed, 09 Oct 2019 16:25:02 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 16:25:02 -03:00

perf beauty: Introduce strtoul() for x86 MSRs

Continuing from the previous cset comment, now that filter expression
works:

  # perf trace -e msr:* --filter="msr!=FS_BASE && msr != IA32_TSC_DEADLINE && 
msr != 0x830 && msr != 0x83f && msr !=IA32_SPEC_CTRL" --filter-pids 3750
 0.000 Timer/5033 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
 0.009 Timer/5033 msr:write_msr(msr: LSTAR, val: -1398800368)
 0.010 Timer/5033 msr:write_msr(msr: TSC_AUX, val: 4)
 0.050 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
45.661 gnome-terminal/12595 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
45.672 gnome-terminal/12595 msr:write_msr(msr: LSTAR, val: -1398800368)
45.675 gnome-terminal/12595 msr:write_msr(msr: TSC_AUX, val: 3)
54.852 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
   130.508 Timer/4050 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
   130.527 Timer/4050 msr:write_msr(msr: LSTAR, val: -1398800368)
   130.531 Timer/4050 msr:write_msr(msr: TSC_AUX, val: 3)
   140.924 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
   164.738 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
   603.578 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
   620.809 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
   690.115 JS Watchdog/4259 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
   690.136 JS Watchdog/4259 msr:write_msr(msr: LSTAR, val: -1398800368)
   690.141 JS Watchdog/4259 msr:write_msr(msr: TSC_AUX, val: 3)
   690.186 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
   759.016 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
^C[root@quaco ~]#

Or look at the first 3 write_msr events for that IA32_TSC_DEADLINE to learn why
it happens so often:

  # perf trace --max-events=3 --max-stack=8 -e msr:* 
--filter="msr==IA32_TSC_DEADLINE" --filter-pids 3750
 0.000 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 19296732550862)
   do_trace_write_msr ([kernel.kallsyms])
   do_trace_write_msr ([kernel.kallsyms])
   lapic_next_deadline ([kernel.kallsyms])
   clockevents_program_event 
([kernel.kallsyms])
   hrtimer_interrupt ([kernel.kallsyms])
   smp_apic_timer_interrupt 
([kernel.kallsyms])
   apic_timer_interrupt ([kernel.kallsyms])
   cpuidle_enter_state ([kernel.kallsyms])
32.646 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 19296800134158)
   do_trace_write_msr ([kernel.kallsyms])
   do_trace_write_msr ([kernel.kallsyms])
   lapic_next_deadline ([kernel.kallsyms])
   clockevents_program_event 
([kernel.kallsyms])
   hrtimer_start_range_ns 
([kernel.kallsyms])
   tick_nohz_restart_sched_tick 
([kernel.kallsyms])
   tick_nohz_idle_exit ([kernel.kallsyms])
   do_idle ([kernel.kallsyms])
32.802 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 19297507436922)
   do_trace_write_msr ([kernel.kallsyms])
   do_trace_write_msr ([kernel.kallsyms])
   lapic_next_deadline ([kernel.kallsyms])
   clockevents_program_event 
([kernel.kallsyms])
   hrtimer_try_to_cancel ([kernel.kallsyms])
   hrtimer_cancel ([kernel.kallsyms])
   tick_nohz_restart_sched_tick 
([kernel.kallsyms])
   tick_nohz_idle_exit ([kernel.kallsyms])
  #

And if some of the strings can't be found:

  # trace -e msr:* --filter="msr!=SPECULATIVE_EXECUTION_PROBLEMS_SOLUTION && 
msr != IA32_TSC_DEADLINE && msr != 0x830 && msr != 0x83f && msr 
!=IA32_SPEC_CTRL" --filter-pids 3750
  "SPECULATIVE_EXECUTION_PROBLEMS_SOLUTION" not found for "msr" in 
"msr:read_msr", can't set filter "(msr!=SPECULATIVE_EXECUTION_PROBLEMS_SOLUTION 
&& msr != IA32_TSC_DEADLINE && msr != 0x830 && msr != 0x83f && msr 
!=IA32_SPEC_CTRL) && (common_pid != 28131 && common_pid != 3750)"
  #

Next step is to automatically wire up the pre-existing strarrays, which there
are quite a few.

The strtoul() methods will be further enhanced to allow for looking at other
arguments in a syscall/tracepoint, 

[tip: perf/core] perf trace: Add array of chars scnprintf beautifier

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 9597945d7fb42460e9f2559d1273302ebde85bbf
Gitweb:
https://git.kernel.org/tip/9597945d7fb42460e9f2559d1273302ebde85bbf
Author:Arnaldo Carvalho de Melo 
AuthorDate:Fri, 04 Oct 2019 14:56:40 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf trace: Add array of chars scnprintf beautifier

Needed for sched's traceoints prev/next comm, where, unlike with
syscalls, we are not dealing with an integer or pointer, but an array
straight out from the ring buffer.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-rlll7tmcqe1g4odtaifil...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index f30296c..b3fb208 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -91,6 +91,7 @@ struct syscall_arg_fmt {
unsigned long (*mask_val)(struct syscall_arg *arg, unsigned long val);
void   *parm;
const char *name;
+   u16nr_entries; // for arrays
bool   show_zero;
 };
 
@@ -522,6 +523,16 @@ size_t syscall_arg__scnprintf_long(char *bf, size_t size, 
struct syscall_arg *ar
return scnprintf(bf, size, "%ld", arg->val);
 }
 
+static size_t syscall_arg__scnprintf_char_array(char *bf, size_t size, struct 
syscall_arg *arg)
+{
+   // XXX Hey, maybe for sched:sched_switch prev/next comm fields we can
+   // fill missing comms using thread__set_comm()...
+   // here or in a special syscall_arg__scnprintf_pid_sched_tp...
+   return scnprintf(bf, size, "\"%-.*s\"", arg->fmt->nr_entries, arg->val);
+}
+
+#define SCA_CHAR_ARRAY syscall_arg__scnprintf_char_array
+
 static const char *bpf_cmd[] = {
"MAP_CREATE", "MAP_LOOKUP_ELEM", "MAP_UPDATE_ELEM", "MAP_DELETE_ELEM",
"MAP_GET_NEXT_KEY", "PROG_LOAD",
@@ -1491,7 +1502,10 @@ syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, 
struct tep_format_field
arg->scnprintf = SCA_PID;
else if (strcmp(field->type, "umode_t") == 0)
arg->scnprintf = SCA_MODE_T;
-   else if ((strcmp(field->type, "int") == 0 ||
+   else if ((field->flags & TEP_FIELD_IS_ARRAY) && 
strstarts(field->type, "char")) {
+   arg->scnprintf = SCA_CHAR_ARRAY;
+   arg->nr_entries = field->arraylen;
+   } else if ((strcmp(field->type, "int") == 0 ||
  strcmp(field->type, "unsigned int") == 0 ||
  strcmp(field->type, "long") == 0) &&
 len >= 2 && strcmp(field->name + len - 2, "fd") == 0) {


[tip: perf/core] perf trace: Allocate an array of beautifiers for tracepoint args

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 947b843cf52a53f6b35aa1406e11884291f41597
Gitweb:
https://git.kernel.org/tip/947b843cf52a53f6b35aa1406e11884291f41597
Author:Arnaldo Carvalho de Melo 
AuthorDate:Thu, 03 Oct 2019 16:18:22 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf trace: Allocate an array of beautifiers for tracepoint args

This will work similar to the syscall args, we'll allocate an array
of 'struct syscall_arg_fmt' for the tracepoint args and then init them
using the same algorithm used for the defaults for syscall args, i.e.
using its types and sometimes names as hints to find the right scnprintf
routine to beautify them from numbers into strings.

Next step is to stop using libtracevent to printf tracepoints, as we'll
have more beautifiers than int provides, modulo perhaps some plugins.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-dcl135relxvf6ljisjg13...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index d52dd2b..aa70602 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1574,6 +1574,19 @@ static int trace__read_syscall_info(struct trace *trace, 
int id)
return syscall__set_arg_fmts(sc);
 }
 
+static int perf_evsel__init_tp_arg_scnprintf(struct evsel *evsel)
+{
+   int nr_args = evsel->tp_format->format.nr_fields;
+
+   evsel->priv = calloc(nr_args, sizeof(struct syscall_arg_fmt));
+   if (evsel->priv != NULL) {
+   syscall_arg_fmt__init_array(evsel->priv, 
evsel->tp_format->format.fields);
+   return 0;
+   }
+
+   return -ENOMEM;
+}
+
 static int intcmp(const void *a, const void *b)
 {
const int *one = a, *another = b;
@@ -3936,8 +3949,10 @@ static int evlist__set_syscall_tp_fields(struct evlist 
*evlist)
if (evsel->priv || !evsel->tp_format)
continue;
 
-   if (strcmp(evsel->tp_format->system, "syscalls"))
+   if (strcmp(evsel->tp_format->system, "syscalls")) {
+   perf_evsel__init_tp_arg_scnprintf(evsel);
continue;
+   }
 
if (perf_evsel__init_syscall_tp(evsel))
return -1;


[tip: perf/core] perf script: Allow --time with --reltime

2019-10-14 Thread tip-bot2 for Andi Kleen
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 3714437d3fcc7956cabcb0077f2a506b61160a56
Gitweb:
https://git.kernel.org/tip/3714437d3fcc7956cabcb0077f2a506b61160a56
Author:Andi Kleen 
AuthorDate:Wed, 02 Oct 2019 09:46:42 -07:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf script: Allow --time with --reltime

The original --reltime patch forbid --time with --reltime.

But it turns out --time doesn't really care about --reltime, because the
relative time is only used at final output, while the time filtering
always works earlier on absolute time.

So just remove the check and allow combining the two options.

Fixes: 90b10f47c0ee ("perf script: Support relative time")
Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lore.kernel.org/lkml/20191002164642.1719-1-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 67be8d3..1c797a9 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3605,11 +3605,6 @@ int cmd_script(int argc, const char **argv)
}
}
 
-   if (script.time_str && reltime) {
-   fprintf(stderr, "Don't combine --reltime with --time\n");
-   return -1;
-   }
-
if (itrace_synth_opts.callchain &&
itrace_synth_opts.callchain_sz > scripting_max_stack)
scripting_max_stack = itrace_synth_opts.callchain_sz;


[tip: perf/core] perf trace: Introduce --filter for tracepoint events

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: d4097f1937f2242d0aa0a7c654d2159a6895e5c8
Gitweb:
https://git.kernel.org/tip/d4097f1937f2242d0aa0a7c654d2159a6895e5c8
Author:Arnaldo Carvalho de Melo 
AuthorDate:Tue, 08 Oct 2019 07:33:08 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf trace: Introduce --filter for tracepoint events

Similar to what is in 'perf record', works just like there:

  # perf trace -e msr:*
   328.297 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.302 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.306 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.317 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.322 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.327 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.331 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.336 :0/0 msr:write_msr(msr: FS_BASE, val: 140240388381888)
   328.340 :0/0 ^Cmsr:write_msr(msr: FS_BASE, val: 140240388381888)
  #

So, for a system wide trace session looking at the write_msr tracepoint
we see a flood of MSR_FS_BASE, we need to get the number for that:

  # grep FS_BASE /tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
[0xc100 - x86_64_specific_MSRs_offset] = "FS_BASE",
  #

And then use it in a filter:

  # perf trace -e msr:* --filter="msr!=0xc100"
  
   942.177 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056931068232)
   942.199 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3057135655252)
   942.203 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056931068222)
   942.231 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056998373022)
   942.241 :0/0 msr:write_msr(msr: IA32_TSC_DEADLINE, val: 3056931068236)
  
  #

Ok, lets filter that too, too noisy:

  # grep TSC_DEADLINE 
/tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
[0x06E0] = "IA32_TSC_DEADLINE",
  #

  # perf trace -e msr:* --filter="msr!=0xc100 && msr!=0x6e0" -a sleep 0.1
 0.000 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
 0.066 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
 0.070 CPU 0/KVM/4895 msr:write_msr(msr: 0x830, val: 34359740667)
 0.099 CPU 0/KVM/4895 msr:read_msr(msr: IA32_SYSENTER_ESP, val: 
-2199021993472)
 0.100 CPU 0/KVM/4895 msr:read_msr(msr: IA32_APICBASE, val: 4276096000)
 0.101 CPU 0/KVM/4895 msr:read_msr(msr: IA32_DEBUGCTLMSR)
 0.109 :0/0 msr:write_msr(msr: IA32_SPEC_CTRL)
 1.000 :0/0 msr:write_msr(msr: 0x830, val: 17179871485)
18.893 :0/0 msr:write_msr(msr: 0x83f, val: 246)
28.810 :0/0 msr:write_msr(msr: 0x830, val: 68719479037)
40.117 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
40.127 CPU 0/KVM/4895 msr:read_msr(msr: IA32_DEBUGCTLMSR)
40.139 CPU 0/KVM/4895 msr:write_msr(msr: LSTAR, val: -2130661312)
40.141 CPU 0/KVM/4895 msr:write_msr(msr: SYSCALL_MASK, val: 14080)
40.142 CPU 0/KVM/4895 msr:write_msr(msr: TSC_AUX)
40.144 CPU 0/KVM/4895 msr:write_msr(msr: KERNEL_GS_BASE)
40.147 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL)
40.148 CPU 0/KVM/4895 msr:write_msr(msr: IA32_FLUSH_CMD, val: 1)
40.151 CPU 0/KVM/4895 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
  ^C
  #

One can combine that with filtering pids as well:

  # perf trace -e msr:* --filter="msr!=0xc100 && msr!=0x6e0" --filter-pids 
4895 -a sleep 0.09
 0.000 :0/0 msr:write_msr(msr: 0x830, val: 4294969597)
 0.291 gnome-terminal/2790 msr:write_msr(msr: SYSCALL_MASK, val: 292608)
 0.294 gnome-terminal/2790 msr:write_msr(msr: LSTAR, val: -1935671280)
 0.295 gnome-terminal/2790 msr:write_msr(msr: TSC_AUX, val: 6)
10.940 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
15.943 gnome-shell/2096 msr:write_msr(msr: 0x830, val: 4294969597)
16.975 :0/0 msr:write_msr(msr: 0x830, val: 4294969597)
19.560 :0/0 msr:write_msr(msr: 0x83f, val: 246)
25.162 :0/0 msr:read_msr(msr: IA32_TSC_ADJUST)
25.807 JS Watchdog/3635 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
25.820 :0/0 msr:write_msr(msr: IA32_SPEC_CTRL)
25.941 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
26.941 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
29.942 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
45.313 :0/0 msr:write_msr(msr: 0x83f, val: 246)
56.945 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
60.946 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 4294969597)
74.096 JS Watchdog/8971 msr:write_msr(msr: IA32_SPEC_CTRL, val: 6)
74.130 :0/0 msr:write_msr(msr: IA32_SPEC_CTRL)
79.673 :0/0 msr:write_msr(msr: 0x83f, val: 246)
79.947 gnome-terminal/2790 msr:write_msr(msr: 0x830, val: 17179871485)
  #

Or for just a pid, with callchains:

  # grep SYSCALL_MAS 

[tip: perf/core] perf tools: Propagate CFLAGS to libperf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 55542113c690a567e728e40d4181d7d037fc21b0
Gitweb:
https://git.kernel.org/tip/55542113c690a567e728e40d4181d7d037fc21b0
Author:Jiri Olsa 
AuthorDate:Fri, 11 Oct 2019 14:21:55 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Fri, 11 Oct 2019 10:55:22 -03:00

perf tools: Propagate CFLAGS to libperf

Andi reported that 'make DEBUG=1' does not propagate to the libbperf
code. It's true also for the other flags. Changing the code to propagate
the global build flags to libperf compilation.

Reported-by: Andi Kleen 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191011122155.15738-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Makefile.config | 28 +++-
 tools/perf/Makefile.perf   |  2 +-
 tools/perf/lib/core.c  |  3 ++-
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 46f7fba..063202c 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -188,7 +188,7 @@ endif
 
 # Treat warnings as errors unless directed not to
 ifneq ($(WERROR),0)
-  CFLAGS += -Werror
+  CORE_CFLAGS += -Werror
   CXXFLAGS += -Werror
 endif
 
@@ -198,9 +198,9 @@ endif
 
 ifeq ($(DEBUG),0)
 ifeq ($(CC_NO_CLANG), 0)
-  CFLAGS += -O3
+  CORE_CFLAGS += -O3
 else
-  CFLAGS += -O6
+  CORE_CFLAGS += -O6
 endif
 endif
 
@@ -245,12 +245,12 @@ FEATURE_CHECK_LDFLAGS-libaio = -lrt
 
 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
 
-CFLAGS += -fno-omit-frame-pointer
-CFLAGS += -ggdb3
-CFLAGS += -funwind-tables
-CFLAGS += -Wall
-CFLAGS += -Wextra
-CFLAGS += -std=gnu99
+CORE_CFLAGS += -fno-omit-frame-pointer
+CORE_CFLAGS += -ggdb3
+CORE_CFLAGS += -funwind-tables
+CORE_CFLAGS += -Wall
+CORE_CFLAGS += -Wextra
+CORE_CFLAGS += -std=gnu99
 
 CXXFLAGS += -std=gnu++11 -fno-exceptions -fno-rtti
 CXXFLAGS += -Wall
@@ -272,12 +272,12 @@ include $(FEATURES_DUMP)
 endif
 
 ifeq ($(feature-stackprotector-all), 1)
-  CFLAGS += -fstack-protector-all
+  CORE_CFLAGS += -fstack-protector-all
 endif
 
 ifeq ($(DEBUG),0)
   ifeq ($(feature-fortify-source), 1)
-CFLAGS += -D_FORTIFY_SOURCE=2
+CORE_CFLAGS += -D_FORTIFY_SOURCE=2
   endif
 endif
 
@@ -301,10 +301,12 @@ INC_FLAGS += -I$(src-perf)/util
 INC_FLAGS += -I$(src-perf)
 INC_FLAGS += -I$(srctree)/tools/lib/
 
-CFLAGS   += $(INC_FLAGS)
+CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+
+CFLAGS   += $(CORE_CFLAGS) $(INC_FLAGS)
 CXXFLAGS += $(INC_FLAGS)
 
-CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
 
 ifeq ($(feature-sync-compare-and-swap), 1)
   CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 45c14dc..a099a8a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -769,7 +769,7 @@ $(LIBBPF)-clean:
$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
 
 $(LIBPERF): FORCE
-   $(Q)$(MAKE) -C $(LIBPERF_DIR) O=$(OUTPUT) $(OUTPUT)libperf.a
+   $(Q)$(MAKE) -C $(LIBPERF_DIR) EXTRA_CFLAGS="$(LIBPERF_CFLAGS)" 
O=$(OUTPUT) $(OUTPUT)libperf.a
 
 $(LIBPERF)-clean:
$(call QUIET_CLEAN, libperf)
diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
index d0b9ae4..58fc894 100644
--- a/tools/perf/lib/core.c
+++ b/tools/perf/lib/core.c
@@ -5,11 +5,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "internal.h"
 
-static int __base_pr(enum libperf_print_level level, const char *format,
+static int __base_pr(enum libperf_print_level level __maybe_unused, const char 
*format,
 va_list args)
 {
return vfprintf(stderr, format, args);


[tip: perf/core] perf scripts python: exported-sql-viewer.py: Add ability for Call tree to open at a specified task and time

2019-10-14 Thread tip-bot2 for Adrian Hunter
The following commit has been merged into the perf/core branch of tip:

Commit-ID: e69d5df75d74da14cbc8c96bbc1d9e86cc91ad0b
Gitweb:
https://git.kernel.org/tip/e69d5df75d74da14cbc8c96bbc1d9e86cc91ad0b
Author:Adrian Hunter 
AuthorDate:Wed, 21 Aug 2019 11:32:15 +03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf scripts python: exported-sql-viewer.py: Add ability for Call tree to open 
at a specified task and time

Add ability for Call tree to open at a specified task and time.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lore.kernel.org/lkml/20190821083216.1340-6-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/exported-sql-viewer.py | 44 ++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index 06b8d55..a5af52f 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -1094,7 +1094,7 @@ class CallGraphWindow(TreeWindowBase):
 
 class CallTreeWindow(TreeWindowBase):
 
-   def __init__(self, glb, parent=None):
+   def __init__(self, glb, parent=None, thread_at_time=None):
super(CallTreeWindow, self).__init__(parent)
 
self.model = LookupCreateModel("Call Tree", lambda x=glb: 
CallTreeModel(x))
@@ -1112,6 +1112,48 @@ class CallTreeWindow(TreeWindowBase):
 
AddSubWindow(glb.mainwindow.mdi_area, self, "Call Tree")
 
+   if thread_at_time:
+   self.DisplayThreadAtTime(*thread_at_time)
+
+   def DisplayThreadAtTime(self, comm_id, thread_id, time):
+   parent = QModelIndex()
+   for dbid in (comm_id, thread_id):
+   found = False
+   n = self.model.rowCount(parent)
+   for row in xrange(n):
+   child = self.model.index(row, 0, parent)
+   if child.internalPointer().dbid == dbid:
+   found = True
+   self.view.setCurrentIndex(child)
+   parent = child
+   break
+   if not found:
+   return
+   found = False
+   while True:
+   n = self.model.rowCount(parent)
+   if not n:
+   return
+   last_child = None
+   for row in xrange(n):
+   child = self.model.index(row, 0, parent)
+   child_call_time = 
child.internalPointer().call_time
+   if child_call_time < time:
+   last_child = child
+   elif child_call_time == time:
+   self.view.setCurrentIndex(child)
+   return
+   elif child_call_time > time:
+   break
+   if not last_child:
+   if not found:
+   child = self.model.index(0, 0, parent)
+   self.view.setCurrentIndex(child)
+   return
+   found = True
+   self.view.setCurrentIndex(last_child)
+   parent = last_child
+
 # Child data item  finder
 
 class ChildDataItemFinder():


[tip: perf/core] perf beauty: Hook up the x86 MSR table generator

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: fd21834704a678a583cf294aea47c7ed3fd9d8d2
Gitweb:
https://git.kernel.org/tip/fd21834704a678a583cf294aea47c7ed3fd9d8d2
Author:Arnaldo Carvalho de Melo 
AuthorDate:Thu, 26 Sep 2019 15:47:16 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf beauty: Hook up the x86 MSR table generator

This way we generate the source with the table for later use by plugins,
etc.

I.e. after running:

  $ make -C tools/perf O=/tmp/build/perf

We end up with:

  $ head /tmp/build/perf/trace/beauty/generated/x86_arch_MSRs_array.c
  static const char *x86_MSRs[] = {
[0x] = "IA32_P5_MC_ADDR",
[0x0001] = "IA32_P5_MC_TYPE",
[0x0010] = "IA32_TSC",
[0x0017] = "IA32_PLATFORM_ID",
[0x001b] = "IA32_APICBASE",
[0x0020] = "KNC_PERFCTR0",
[0x0021] = "KNC_PERFCTR1",
[0x0028] = "KNC_EVNTSEL0",
[0x0029] = "KNC_EVNTSEL1",
  $

Now its just a matter of using it, first in a libtracevent plugin.

At some point we should move tools/perf/trace/beauty to tools/beauty/,
so that it can be used more generally and even made available externally
like libbpf, libperf, libtraevent, etc.

Cc: Adrian Hunter 
Cc: Brendan Gregg 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-b3rmutg4igcohx6kpo67q...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Makefile.perf |  9 +
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 902c792..45c14dc 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -407,6 +407,7 @@ linux_uapi_dir := $(srctree)/tools/include/uapi/linux
 asm_generic_uapi_dir := $(srctree)/tools/include/uapi/asm-generic
 arch_asm_uapi_dir := $(srctree)/tools/arch/$(SRCARCH)/include/uapi/asm/
 x86_arch_asm_uapi_dir := $(srctree)/tools/arch/x86/include/uapi/asm/
+x86_arch_asm_dir := $(srctree)/tools/arch/x86/include/asm/
 
 beauty_outdir := $(OUTPUT)trace/beauty/generated
 beauty_ioctl_outdir := $(beauty_outdir)/ioctl
@@ -543,6 +544,12 @@ x86_arch_prctl_code_tbl := 
$(srctree)/tools/perf/trace/beauty/x86_arch_prctl.sh
 $(x86_arch_prctl_code_array): $(x86_arch_asm_uapi_dir)/prctl.h 
$(x86_arch_prctl_code_tbl)
$(Q)$(SHELL) '$(x86_arch_prctl_code_tbl)' $(x86_arch_asm_uapi_dir) > $@
 
+x86_arch_MSRs_array := $(beauty_outdir)/x86_arch_MSRs_array.c
+x86_arch_MSRs_tbl := $(srctree)/tools/perf/trace/beauty/tracepoints/x86_msr.sh
+
+$(x86_arch_MSRs_array): $(x86_arch_asm_dir)/msr-index.h $(x86_arch_MSRs_tbl)
+   $(Q)$(SHELL) '$(x86_arch_MSRs_tbl)' $(x86_arch_asm_dir) > $@
+
 rename_flags_array := $(beauty_outdir)/rename_flags_array.c
 rename_flags_tbl := $(srctree)/tools/perf/trace/beauty/rename_flags.sh
 
@@ -677,6 +684,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h 
archheaders $(drm_ioc
$(perf_ioctl_array) \
$(prctl_option_array) \
$(usbdevfs_ioctl_array) \
+   $(x86_arch_MSRs_array) \
$(x86_arch_prctl_code_array) \
$(rename_flags_array) \
$(arch_errno_name_array) \
@@ -981,6 +989,7 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean 
$(LIBBPF)-clean $(LIBSUBCMD)-clea
$(OUTPUT)$(perf_ioctl_array) \
$(OUTPUT)$(prctl_option_array) \
$(OUTPUT)$(usbdevfs_ioctl_array) \
+   $(OUTPUT)$(x86_arch_MSRs_array) \
$(OUTPUT)$(x86_arch_prctl_code_array) \
$(OUTPUT)$(rename_flags_array) \
$(OUTPUT)$(arch_errno_name_array) \


[tip: perf/core] perf trace: Postpone parsing .perfconfig trace.add_events to after --verbose is processed

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 7e035929f3fec70d411fb660c434f4a7f8ca386d
Gitweb:
https://git.kernel.org/tip/7e035929f3fec70d411fb660c434f4a7f8ca386d
Author:Arnaldo Carvalho de Melo 
AuthorDate:Tue, 01 Oct 2019 15:44:44 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf trace: Postpone parsing .perfconfig trace.add_events to after --verbose is 
processed

When we add events via the '[trace]' section in perfconfig the command
line options are not yet processed, so when something goes wrong with
parsing those events and using --verbose is advised, we end up not
getting any more verbosity by doing so.

So just copy the trace.add_events string for later processing, after we
processed --verbose and the other command line options.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-d6wbnz85ftqljdll6ynjy...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 31 ++-
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 313dfc1..3d54316 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -162,6 +162,7 @@ struct trace {
boolforce;
boolvfs_getname;
int trace_pgfaults;
+   char*perfconfig_events;
struct {
struct ordered_events   data;
u64 last;
@@ -4044,15 +4045,11 @@ static int trace__config(const char *var, const char 
*value, void *arg)
int err = 0;
 
if (!strcmp(var, "trace.add_events")) {
-   struct option o = OPT_CALLBACK('e', "event", >evlist, 
"event",
-  "event selector. use 'perf list' 
to list available events",
-  parse_events_option);
-   /*
-* We can't propagate parse_event_option() return, as it is 1
-* for failure while perf_config() expects -1.
-*/
-   if (parse_events_option(, value, 0))
-   err = -1;
+   trace->perfconfig_events = strdup(value);
+   if (trace->perfconfig_events == NULL) {
+   pr_err("Not enough memory for %s\n", 
"trace.add_events");
+   return -1;
+   }
} else if (!strcmp(var, "trace.show_timestamp")) {
trace->show_tstamp = perf_config_bool(var, value);
} else if (!strcmp(var, "trace.show_duration")) {
@@ -4224,6 +4221,21 @@ int cmd_trace(int argc, const char **argv)
 
argc = parse_options_subcommand(argc, argv, trace_options, 
trace_subcommands,
 trace_usage, PARSE_OPT_STOP_AT_NON_OPTION);
+   /*
+* Now that we have --verbose figured out, lets see if we need to parse
+* events from .perfconfig, so that if those events fail parsing, say 
some
+* BPF program fails, then we'll be able to use --verbose to see what 
went
+* wrong in more detail.
+*/
+   if (trace.perfconfig_events != NULL) {
+   struct parse_events_error parse_err = { .idx = 0, };
+
+   err = parse_events(trace.evlist, trace.perfconfig_events, 
_err);
+   if (err) {
+   parse_events_print_error(_err, 
trace.perfconfig_events);
+   goto out;
+   }
+   }
 
if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) {
usage_with_options_msg(trace_usage, trace_options,
@@ -4441,5 +4453,6 @@ out_close:
if (output_name != NULL)
fclose(trace.output);
 out:
+   zfree(_events);
return err;
 }


[tip: perf/core] perf trace: Generalize the syscall_fmt find routines

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: bcddbfc5c8c952175e9a5f1a4186685fa0338a14
Gitweb:
https://git.kernel.org/tip/bcddbfc5c8c952175e9a5f1a4186685fa0338a14
Author:Arnaldo Carvalho de Melo 
AuthorDate:Tue, 01 Oct 2019 15:27:55 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf trace: Generalize the syscall_fmt find routines

To allow them to be used with other stuff, such as tracepoints.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-od3gzg77ppqgnnrxqv40f...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index cb85343..313dfc1 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -966,24 +966,35 @@ static int syscall_fmt__cmp(const void *name, const void 
*fmtp)
return strcmp(name, fmt->name);
 }
 
+static struct syscall_fmt *__syscall_fmt__find(struct syscall_fmt *fmts, const 
int nmemb, const char *name)
+{
+   return bsearch(name, fmts, nmemb, sizeof(struct syscall_fmt), 
syscall_fmt__cmp);
+}
+
 static struct syscall_fmt *syscall_fmt__find(const char *name)
 {
const int nmemb = ARRAY_SIZE(syscall_fmts);
-   return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), 
syscall_fmt__cmp);
+   return __syscall_fmt__find(syscall_fmts, nmemb, name);
 }
 
-static struct syscall_fmt *syscall_fmt__find_by_alias(const char *alias)
+static struct syscall_fmt *__syscall_fmt__find_by_alias(struct syscall_fmt 
*fmts, const int nmemb, const char *alias)
 {
-   int i, nmemb = ARRAY_SIZE(syscall_fmts);
+   int i;
 
for (i = 0; i < nmemb; ++i) {
-   if (syscall_fmts[i].alias && strcmp(syscall_fmts[i].alias, 
alias) == 0)
-   return _fmts[i];
+   if (fmts[i].alias && strcmp(fmts[i].alias, alias) == 0)
+   return [i];
}
 
return NULL;
 }
 
+static struct syscall_fmt *syscall_fmt__find_by_alias(const char *alias)
+{
+   const int nmemb = ARRAY_SIZE(syscall_fmts);
+   return __syscall_fmt__find_by_alias(syscall_fmts, nmemb, alias);
+}
+
 /*
  * is_exit: is this "exit" or "exit_group"?
  * is_open: is this "open" or "openat"? To associate the fd returned in 
sys_exit with the pathname in sys_enter.


[tip: perf/core] libperf: Move the pollfd allocation from tools/perf to libperf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 230662e15ed6cc63ecf72ed1bffa3cadef486850
Gitweb:
https://git.kernel.org/tip/230662e15ed6cc63ecf72ed1bffa3cadef486850
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:31 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:54:35 -03:00

libperf: Move the pollfd allocation from tools/perf to libperf

It's needed in libperf only, so move it to the perf_evlist__mmap_ops()
function.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-24-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 5 +
 tools/perf/util/evlist.c | 4 
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index f9a802d..5ae1da9 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -34,6 +34,7 @@ void perf_evlist__init(struct perf_evlist *evlist)
INIT_HLIST_HEAD(>heads[i]);
INIT_LIST_HEAD(>entries);
evlist->nr_entries = 0;
+   fdarray__init(>pollfd, 64);
 }
 
 static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
@@ -114,6 +115,7 @@ void perf_evlist__delete(struct perf_evlist *evlist)
return;
 
perf_evlist__munmap(evlist);
+   fdarray__exit(>pollfd);
free(evlist);
 }
 
@@ -525,6 +527,9 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
return -ENOMEM;
}
 
+   if (evlist->pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) 
< 0)
+   return -ENOMEM;
+
if (perf_cpu_map__empty(cpus))
return mmap_per_thread(evlist, ops, mp);
 
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 3f4f11f..5192c65 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -58,7 +58,6 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map 
*cpus,
 {
perf_evlist__init(>core);
perf_evlist__set_maps(>core, cpus, threads);
-   fdarray__init(>core.pollfd, 64);
evlist->workload.pid = -1;
evlist->bkw_mmap_state = BKW_MMAP_NOTREADY;
 }
@@ -829,9 +828,6 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int 
pages,
if (!evlist->mmap)
return -ENOMEM;
 
-   if (evlist->core.pollfd.entries == NULL && 
perf_evlist__alloc_pollfd(>core) < 0)
-   return -ENOMEM;
-
evlist->core.mmap_len = evlist__mmap_size(pages);
pr_debug("mmap size %zuB\n", evlist->core.mmap_len);
mp.core.mask = evlist->core.mmap_len - page_size - 1;


[tip: perf/core] perf evlist: Adopt __set_tracepoint_handlers method from perf_session

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: c0e53476ab5087353547cbcd37f001d98941326c
Gitweb:
https://git.kernel.org/tip/c0e53476ab5087353547cbcd37f001d98941326c
Author:Arnaldo Carvalho de Melo 
AuthorDate:Tue, 01 Oct 2019 11:14:26 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf evlist: Adopt __set_tracepoint_handlers method from perf_session

It all operates on the evsels in the session's evlist, so move it to the
evlist layer to make it useful to tools not using perf_session, just
evlists, like 'perf trace' in live mode.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-9oc53gnfi53vg82fvolkm...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c  | 24 
 tools/perf/util/evlist.h  |  7 +++
 tools/perf/util/session.c | 29 -
 tools/perf/util/session.h |  6 +-
 4 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index d277a98..b4c43ac 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -186,6 +186,30 @@ void perf_evlist__splice_list_tail(struct evlist *evlist,
}
 }
 
+int __evlist__set_tracepoints_handlers(struct evlist *evlist,
+  const struct evsel_str_handler *assocs, 
size_t nr_assocs)
+{
+   struct evsel *evsel;
+   size_t i;
+   int err;
+
+   for (i = 0; i < nr_assocs; i++) {
+   // Adding a handler for an event not in this evlist, just 
ignore it.
+   evsel = perf_evlist__find_tracepoint_by_name(evlist, 
assocs[i].name);
+   if (evsel == NULL)
+   continue;
+
+   err = -EEXIST;
+   if (evsel->handler != NULL)
+   goto out;
+   evsel->handler = assocs[i].handler;
+   }
+
+   err = 0;
+out:
+   return err;
+}
+
 void __perf_evlist__set_leader(struct list_head *list)
 {
struct evsel *evsel, *leader;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 7cfe755..00eab94 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -118,6 +118,13 @@ void perf_evlist__stop_sb_thread(struct evlist *evlist);
 int perf_evlist__add_newtp(struct evlist *evlist,
   const char *sys, const char *name, void *handler);
 
+int __evlist__set_tracepoints_handlers(struct evlist *evlist,
+  const struct evsel_str_handler *assocs,
+  size_t nr_assocs);
+
+#define evlist__set_tracepoints_handlers(evlist, array) \
+   __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
+
 void __perf_evlist__set_sample_bit(struct evlist *evlist,
   enum perf_event_sample_format bit);
 void __perf_evlist__reset_sample_bit(struct evlist *evlist,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 061bb4d..6cc32f5 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2355,35 +2355,6 @@ void perf_session__fprintf_info(struct perf_session 
*session, FILE *fp,
fprintf(fp, "# \n#\n");
 }
 
-
-int __perf_session__set_tracepoints_handlers(struct perf_session *session,
-const struct evsel_str_handler 
*assocs,
-size_t nr_assocs)
-{
-   struct evsel *evsel;
-   size_t i;
-   int err;
-
-   for (i = 0; i < nr_assocs; i++) {
-   /*
-* Adding a handler for an event not in the session,
-* just ignore it.
-*/
-   evsel = perf_evlist__find_tracepoint_by_name(session->evlist, 
assocs[i].name);
-   if (evsel == NULL)
-   continue;
-
-   err = -EEXIST;
-   if (evsel->handler != NULL)
-   goto out;
-   evsel->handler = assocs[i].handler;
-   }
-
-   err = 0;
-out:
-   return err;
-}
-
 int perf_event__process_id_index(struct perf_session *session,
 union perf_event *event)
 {
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index b4c9428..8456e1d 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -120,12 +120,8 @@ void perf_session__fprintf_info(struct perf_session *s, 
FILE *fp, bool full);
 
 struct evsel_str_handler;
 
-int __perf_session__set_tracepoints_handlers(struct perf_session *session,
-const struct evsel_str_handler 
*assocs,
-size_t nr_assocs);
-
 #define perf_session__set_tracepoints_handlers(session, array) \
-   __perf_session__set_tracepoints_handlers(session, array, 

[tip: perf/core] perf env: Add routine to read the env->cpuid from the running machine

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: f1cedfb82858c8a7ec21e45d0ce7b6e2ce9edea0
Gitweb:
https://git.kernel.org/tip/f1cedfb82858c8a7ec21e45d0ce7b6e2ce9edea0
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 30 Sep 2019 11:50:15 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf env: Add routine to read the env->cpuid from the running machine

In 'perf top' we use that cpuid when initializing the per arch
annotation init routines (e.g. x86__annotate_init()) and in that case
(live mode, 'perf top') we need to obtain it from the running machine,
not from a perf.data file header.

Provide a means to do that. Will be used by 'perf top' in a followup
patch.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-h2wb3sx7u7znx6lqfezrh...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/env.c | 16 
 tools/perf/util/env.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 3baca06..2a91a10 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -2,6 +2,7 @@
 #include "cpumap.h"
 #include "debug.h"
 #include "env.h"
+#include "util/header.h"
 #include 
 #include 
 #include "bpf-event.h"
@@ -256,6 +257,21 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)
return 0;
 }
 
+int perf_env__read_cpuid(struct perf_env *env)
+{
+   char cpuid[128];
+   int err = get_cpuid(cpuid, sizeof(cpuid));
+
+   if (err)
+   return err;
+
+   free(env->cpuid);
+   env->cpuid = strdup(cpuid);
+   if (env->cpuid == NULL)
+   return ENOMEM;
+   return 0;
+}
+
 static int perf_env__read_arch(struct perf_env *env)
 {
struct utsname uts;
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index db40906..a3059dc 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -104,6 +104,7 @@ void perf_env__exit(struct perf_env *env);
 
 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
 
+int perf_env__read_cpuid(struct perf_env *env);
 int perf_env__read_cpu_topology_map(struct perf_env *env);
 
 void cpu_cache_level__free(struct cpu_cache_level *cache);


[tip: perf/core] tools arch x86: Grab a copy of the file containing the MSR numbers

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 444e2ff34df8f631cd83ae73bb56ef13cfb84b34
Gitweb:
https://git.kernel.org/tip/444e2ff34df8f631cd83ae73bb56ef13cfb84b34
Author:Arnaldo Carvalho de Melo 
AuthorDate:Thu, 26 Sep 2019 15:26:39 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

tools arch x86: Grab a copy of the file containing the MSR numbers

We'll use it to generate a table and then convert the
msr:{read,write}_msr 'msr' option in things like perf trace, script,
etc.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-y1f4s0y1s43d4drh7pd2h...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/arch/x86/include/asm/msr-index.h | 857 -
 tools/perf/check-headers.sh|   1 +-
 2 files changed, 858 insertions(+)
 create mode 100644 tools/arch/x86/include/asm/msr-index.h

diff --git a/tools/arch/x86/include/asm/msr-index.h 
b/tools/arch/x86/include/asm/msr-index.h
new file mode 100644
index 000..20ce682
--- /dev/null
+++ b/tools/arch/x86/include/asm/msr-index.h
@@ -0,0 +1,857 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_MSR_INDEX_H
+#define _ASM_X86_MSR_INDEX_H
+
+#include 
+
+/*
+ * CPU model specific register (MSR) numbers.
+ *
+ * Do not add new entries to this file unless the definitions are shared
+ * between multiple compilation units.
+ */
+
+/* x86-64 specific MSRs */
+#define MSR_EFER   0xc080 /* extended feature register */
+#define MSR_STAR   0xc081 /* legacy mode SYSCALL target */
+#define MSR_LSTAR  0xc082 /* long mode SYSCALL target */
+#define MSR_CSTAR  0xc083 /* compat mode SYSCALL target */
+#define MSR_SYSCALL_MASK   0xc084 /* EFLAGS mask for syscall */
+#define MSR_FS_BASE0xc100 /* 64bit FS base */
+#define MSR_GS_BASE0xc101 /* 64bit GS base */
+#define MSR_KERNEL_GS_BASE 0xc102 /* SwapGS GS shadow */
+#define MSR_TSC_AUX0xc103 /* Auxiliary TSC */
+
+/* EFER bits: */
+#define _EFER_SCE  0  /* SYSCALL/SYSRET */
+#define _EFER_LME  8  /* Long mode enable */
+#define _EFER_LMA  10 /* Long mode active (read-only) */
+#define _EFER_NX   11 /* No execute enable */
+#define _EFER_SVME 12 /* Enable virtualization */
+#define _EFER_LMSLE13 /* Long Mode Segment Limit Enable */
+#define _EFER_FFXSR14 /* Enable Fast FXSAVE/FXRSTOR */
+
+#define EFER_SCE   (1<<_EFER_SCE)
+#define EFER_LME   (1<<_EFER_LME)
+#define EFER_LMA   (1<<_EFER_LMA)
+#define EFER_NX(1<<_EFER_NX)
+#define EFER_SVME  (1<<_EFER_SVME)
+#define EFER_LMSLE (1<<_EFER_LMSLE)
+#define EFER_FFXSR (1<<_EFER_FFXSR)
+
+/* Intel MSRs. Some also available on other CPUs */
+
+#define MSR_IA32_SPEC_CTRL 0x0048 /* Speculation Control */
+#define SPEC_CTRL_IBRS BIT(0) /* Indirect Branch 
Restricted Speculation */
+#define SPEC_CTRL_STIBP_SHIFT  1  /* Single Thread Indirect 
Branch Predictor (STIBP) bit */
+#define SPEC_CTRL_STIBPBIT(SPEC_CTRL_STIBP_SHIFT)  
/* STIBP mask */
+#define SPEC_CTRL_SSBD_SHIFT   2  /* Speculative Store Bypass 
Disable bit */
+#define SPEC_CTRL_SSBD BIT(SPEC_CTRL_SSBD_SHIFT)   /* 
Speculative Store Bypass Disable */
+
+#define MSR_IA32_PRED_CMD  0x0049 /* Prediction Command */
+#define PRED_CMD_IBPB  BIT(0) /* Indirect Branch 
Prediction Barrier */
+
+#define MSR_PPIN_CTL   0x004e
+#define MSR_PPIN   0x004f
+
+#define MSR_IA32_PERFCTR0  0x00c1
+#define MSR_IA32_PERFCTR1  0x00c2
+#define MSR_FSB_FREQ   0x00cd
+#define MSR_PLATFORM_INFO  0x00ce
+#define MSR_PLATFORM_INFO_CPUID_FAULT_BIT  31
+#define MSR_PLATFORM_INFO_CPUID_FAULT  
BIT_ULL(MSR_PLATFORM_INFO_CPUID_FAULT_BIT)
+
+#define MSR_IA32_UMWAIT_CONTROL0xe1
+#define MSR_IA32_UMWAIT_CONTROL_C02_DISABLEBIT(0)
+#define MSR_IA32_UMWAIT_CONTROL_RESERVED   BIT(1)
+/*
+ * The time field is bit[31:2], but representing a 32bit value with
+ * bit[1:0] zero.
+ */
+#define MSR_IA32_UMWAIT_CONTROL_TIME_MASK  (~0x03U)
+
+#define MSR_PKG_CST_CONFIG_CONTROL 0x00e2
+#define NHM_C3_AUTO_DEMOTE (1UL << 25)
+#define NHM_C1_AUTO_DEMOTE (1UL << 26)
+#define ATM_LNC_C6_AUTO_DEMOTE (1UL << 25)
+#define SNB_C3_AUTO_UNDEMOTE   (1UL << 27)
+#define SNB_C1_AUTO_UNDEMOTE   (1UL << 28)
+
+#define MSR_MTRRcap0x00fe
+
+#define MSR_IA32_ARCH_CAPABILITIES 0x010a
+#define ARCH_CAP_RDCL_NO

[tip: perf/core] samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

2019-10-14 Thread tip-bot2 for Björn Töpel
The following commit has been merged into the perf/core branch of tip:

Commit-ID: fce9501aec6bdda45ef3a5e365a5e0de7de7fe2d
Gitweb:
https://git.kernel.org/tip/fce9501aec6bdda45ef3a5e365a5e0de7de7fe2d
Author:Björn Töpel 
AuthorDate:Tue, 01 Oct 2019 13:33:07 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

samples/bpf: fix build by setting HAVE_ATTR_TEST to zero

To remove that test_attr__{enabled/open} are used by perf-sys.h, we
set HAVE_ATTR_TEST to zero.

Signed-off-by: Björn Töpel 
Tested-by: KP Singh 
Acked-by: Song Liu 
Cc: Adrian Hunter 
Cc: Alexei Starovoitov 
Cc: Daniel Borkmann 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: b...@vger.kernel.org
Cc: net...@vger.kernel.org
Link: http://lore.kernel.org/lkml/20191001113307.27796-3-bjorn.to...@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 samples/bpf/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 1d9be26..42b571c 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -176,6 +176,7 @@ KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/bpf/
 KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
 KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
 KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
+KBUILD_HOSTCFLAGS += -DHAVE_ATTR_TEST=0
 
 HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
 


[tip: perf/core] perf trace: Make evlist__set_evsel_handler() affect just entries without a handler

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 206d635aa594a5246cd181b3be39d1e3b2126f68
Gitweb:
https://git.kernel.org/tip/206d635aa594a5246cd181b3be39d1e3b2126f68
Author:Arnaldo Carvalho de Melo 
AuthorDate:Tue, 01 Oct 2019 11:31:59 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf trace: Make evlist__set_evsel_handler() affect just entries without a 
handler

Renaming it to evlist__set_default_evsel_handler(), to better reflect
what we want to do, which is to set a default handler for events we
still haven't set a custom handler, like the ones for "msr:write_msr",
etc that are coming soon.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-e1bit7upnpmtsayh8039k...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index bb5130d..ee330f5 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3858,12 +3858,14 @@ static int parse_pagefaults(const struct option *opt, 
const char *str,
return 0;
 }
 
-static void evlist__set_evsel_handler(struct evlist *evlist, void *handler)
+static void evlist__set_default_evsel_handler(struct evlist *evlist, void 
*handler)
 {
struct evsel *evsel;
 
-   evlist__for_each_entry(evlist, evsel)
-   evsel->handler = handler;
+   evlist__for_each_entry(evlist, evsel) {
+   if (evsel->handler == NULL)
+   evsel->handler = handler;
+   }
 }
 
 static int evlist__set_syscall_tp_fields(struct evlist *evlist)
@@ -4287,7 +4289,7 @@ int cmd_trace(int argc, const char **argv)
}
 
if (trace.evlist->core.nr_entries > 0) {
-   evlist__set_evsel_handler(trace.evlist, trace__event_handler);
+   evlist__set_default_evsel_handler(trace.evlist, 
trace__event_handler);
if (evlist__set_syscall_tp_fields(trace.evlist)) {
perror("failed to set syscalls:* tracepoint fields");
goto out;


[tip: perf/core] perf diff: Report noisy for cycles diff

2019-10-14 Thread tip-bot2 for Jin Yao
The following commit has been merged into the perf/core branch of tip:

Commit-ID: cebf7d51a6c3babc4d0589da7aec0de1af0a5691
Gitweb:
https://git.kernel.org/tip/cebf7d51a6c3babc4d0589da7aec0de1af0a5691
Author:Jin Yao 
AuthorDate:Wed, 25 Sep 2019 09:14:46 +08:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Fri, 11 Oct 2019 10:57:00 -03:00

perf diff: Report noisy for cycles diff

This patch prints the stddev and hist for the cycles diff of program
block. It can help us to understand if the cycles is noisy or not.

This patch is inspired by Andi Kleen's patch:

  https://lwn.net/Articles/600471/

We create new option '--cycles-hist'.

Example:

  perf record -b ./div
  perf record -b ./div
  perf diff -c cycles

  # Baseline[Program Block Range] Cycles Diff  
Shared Object  Symbol
  #   ..   
.  
  #
  46.72%  [div.c:40 -> div.c:40]0  
div[.] main
  46.72%  [div.c:42 -> div.c:44]0  
div[.] main
  46.72%  [div.c:42 -> div.c:39]0  
div[.] main
  20.54%  [random_r.c:357 -> random_r.c:394]1  
libc-2.27.so   [.] __random_r
  20.54%  [random_r.c:357 -> random_r.c:380]0  
libc-2.27.so   [.] __random_r
  20.54%  [random_r.c:388 -> random_r.c:388]0  
libc-2.27.so   [.] __random_r
  20.54%  [random_r.c:388 -> random_r.c:391]0  
libc-2.27.so   [.] __random_r
  17.04%  [random.c:288 -> random.c:291]0  
libc-2.27.so   [.] __random
  17.04%  [random.c:291 -> random.c:291]0  
libc-2.27.so   [.] __random
  17.04%  [random.c:293 -> random.c:293]0  
libc-2.27.so   [.] __random
  17.04%  [random.c:295 -> random.c:295]0  
libc-2.27.so   [.] __random
  17.04%  [random.c:295 -> random.c:295]0  
libc-2.27.so   [.] __random
  17.04%  [random.c:298 -> random.c:298]0  
libc-2.27.so   [.] __random
   8.40%  [div.c:22 -> div.c:25]0  
div[.] compute_flag
   8.40%  [div.c:27 -> div.c:28]0  
div[.] compute_flag
   5.14%[rand.c:26 -> rand.c:27]0  
libc-2.27.so   [.] rand
   5.14%[rand.c:28 -> rand.c:28]0  
libc-2.27.so   [.] rand
   2.15%  [rand@plt+0 -> rand@plt+0]0  
div[.] rand@plt
   0.00%   
[kernel.kallsyms]  [k] __x86_indirect_thunk_rax
   0.00%[do_mmap+714 -> do_mmap+732]  -10  
[kernel.kallsyms]  [k] do_mmap
   0.00%[do_mmap+737 -> do_mmap+765]1  
[kernel.kallsyms]  [k] do_mmap
   0.00%[do_mmap+262 -> do_mmap+299]0  
[kernel.kallsyms]  [k] do_mmap
   0.00%  [__x86_indirect_thunk_r15+0 -> __x86_indirect_thunk_r15+0]7  
[kernel.kallsyms]  [k] __x86_indirect_thunk_r15
   0.00%[native_sched_clock+0 -> native_sched_clock+119]   -1  
[kernel.kallsyms]  [k] native_sched_clock
   0.00% [native_write_msr+0 -> native_write_msr+16]  -13  
[kernel.kallsyms]  [k] native_write_msr

When we enable the option '--cycles-hist', the output is

  perf diff -c cycles --cycles-hist

  # Baseline[Program Block Range] Cycles Diff   
 stddev/Hist  Shared Object  Symbol
  #   ..   
.  .  
  #
  46.72%  [div.c:40 -> div.c:40]0  
± 37.8% ▁█▁▁██▁█   div[.] main
  46.72%  [div.c:42 -> div.c:44]0  
± 49.4% ▁▁▂█   div[.] main
  46.72%  [div.c:42 -> div.c:39]0  
± 24.1% ▃█▂▄▁▃▂▁   div[.] main
  20.54%  [random_r.c:357 -> random_r.c:394]1  
± 33.5% ▅▂▁█▃▁▂▁   libc-2.27.so   [.] __random_r
  20.54%  [random_r.c:357 -> random_r.c:380]0  
± 39.4% ▁▁█▁██▅▁   libc-2.27.so   [.] __random_r
  20.54%  [random_r.c:388 -> random_r.c:388]0   
  libc-2.27.so   [.] __random_r
  20.54% 

[tip: perf/core] perf trace augmented_syscalls: Do not show syscalls when none was asked for

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 8bd436b006d4493964c310606f2eb8e56680126c
Gitweb:
https://git.kernel.org/tip/8bd436b006d4493964c310606f2eb8e56680126c
Author:Arnaldo Carvalho de Melo 
AuthorDate:Wed, 02 Oct 2019 12:54:07 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf trace augmented_syscalls: Do not show syscalls when none was asked for

When not using augmented syscalls, i.e. not passing thru the command
line a eBPF source or object file event that provides the
__augmented_syscalls__ BPF_MAP_TYPE_PERF_EVENT_ARRAY, etc, as with:

   perf trace -e tools/perf/examples/bpf/augmented_raw_syscalls.c

or passing that augmented eBPF source/object via the trace.add_events in
.perfconfig file, we were assuming that syscalls were asked for,
differing from when not using augmented syscalls at all.

This is confusing when using .perfconfig to hide the fact we're using
the augmenter, i.e. using:

 # perf trace -e sched:* sleep 1

Will show both the scheduler tracepoints and the syscalls, where what we
want is to show just the scheduler tracepoints.

To see the scheduler tracepoints and some specific syscall strace-like
formatting, one has to use:

  # perf trace -e sched:*,nanosleep sleep 1

Or, if wanting all the syscalls:

  # perf trace -e sched:* --syscalls sleep 1

This way 'perf trace' can be used to trace just a set of tracepoints
while allowing for mixing with strace-like when desired, by simply
adding to the mix the name of the syscalls to show in addition to the
tracepoints.

Fix it so that the behaviour using the eBPF based syscall augmenter is
the same as when not using one.

Testing:

Before this patch, with this ~/.perfconfig:

  # egrep -B1 ^[[:space:]]+add_events ~/.perfconfig
  [trace]
add_events = 
/home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
  #

That points to this pre-compiled eBPF syscall augmenter:

  # file /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
  /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o: ELF 
64-bit LSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped

And when asking for _only_ sched:sched_switch and sched:sched_wakeup we
were unconditionally getting all the syscalls formatted strace-like:

  # perf trace -e sched:*switch,sched:*wakeup sleep 1 |& tail
 0.633 fstat(3, 0x7fe11d030ac0)= 0
 0.635 mmap(NULL, 217750512, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fe10fec5000
 0.643 close(3)= 0
 0.668 nanosleep(0x7fff649a3a90, NULL)  ...
 0.672 sched:sched_switch:prev_comm=sleep prev_pid=4417 prev_prio=120 
prev_state=S ==> next_comm=swapper/6 next_pid=0 next_prio=120
  1000.822 sched:sched_wakeup:comm=sleep pid=4417 prio=120 target_cpu=006
 0.668  ... [continued]: nanosleep())  = 0
  1000.923 close(1)= 0
  1000.941 close(2)= 0
  1000.974 exit_group(0)   = ?
  #

After the patch:

  # perf trace -e sched:*switch,sched:*wakeup sleep 1
 0.000 sched:sched_wakeup:comm=perf pid=5529 prio=120 target_cpu=005
 1.186 sched:sched_switch:prev_comm=sleep prev_pid=5529 prev_prio=120 
prev_state=S ==> next_comm=swapper/5 next_pid=0 next_prio=120
  1001.573 sched:sched_wakeup:comm=sleep pid=5529 prio=120 target_cpu=005
  #

If we add the "open*" syscalls to the mix then the eBPF augmented _will_
be used and these syscalls will be traced together with the specified
sched tracepoints:

  # cd /sys/kernel/debug/tracing/events/syscalls/
  # ls -1d sys_enter_open*
  sys_enter_open
  sys_enter_openat
  sys_enter_open_by_handle_at
  sys_enter_open_tree
  #

  # perf trace -e open*,sched:*switch,sched:*wakeup sleep 1
   0.000 sched:sched_wakeup:comm=perf pid=5580 prio=120 target_cpu=005
   0.590 openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
   0.616 openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
   0.846 openat(AT_FDCWD, "/usr/lib/locale/locale-archive", 
O_RDONLY|O_CLOEXEC) = 3
   0.891 sched:sched_switch:prev_comm=sleep prev_pid=5580 prev_prio=120 
prev_state=S ==> next_comm=swapper/5 next_pid=0 next_prio=120
1001.005 sched:sched_wakeup:comm=sleep pid=5580 prio=120 target_cpu=005
  #

And as we can see, the pathnames were collected via the eBPF augmenters.

If we don't specify anything it'll trace all syscalls:

  # perf trace sleep 1 |& tail
   0.299 brk(0x5597543a3000) = 0x5597543a3000
   0.302 brk(NULL)   = 0x5597543a3000
   0.307 openat(AT_FDCWD, "/usr/lib/locale/locale-archive", 
O_RDONLY|O_CLOEXEC) = 3
   0.313 fstat(3, 0x7feece50cac0)= 0
   0.315 mmap(NULL, 217750512, PROT_READ, MAP_PRIVATE, 3, 0) = 
0x7feec13a1000
   0.323 close(3)= 0
   

[tip: perf/core] perf top: Initialize perf_env->cpuid, needed by the per arch annotation init routine

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 608127f73779bfc199158b61efdbdb690720e542
Gitweb:
https://git.kernel.org/tip/608127f73779bfc199158b61efdbdb690720e542
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 30 Sep 2019 11:53:00 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf top: Initialize perf_env->cpuid, needed by the per arch annotation init 
routine

Just read it so that later on the per arch init routine can use it,
e.g. x86__annotate_init().

When using a perf.data file this is obtained from a header that was put
there by 'perf record', and then it may be for another machine, another
arch.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-4t4n3o8l8s0tc2b1pq53h...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-top.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 1f60124..611d030 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1560,6 +1560,17 @@ int cmd_top(int argc, const char **argv)
status = perf_config(perf_top_config, );
if (status)
return status;
+   /*
+* Since the per arch annotation init routine may need the cpuid, read
+* it here, since we are not getting this from the perf.data header.
+*/
+   status = perf_env__read_cpuid(_env);
+   if (status) {
+   pr_err("Couldn't read the cpuid for this machine: %s\n",
+  str_error_r(errno, errbuf, sizeof(errbuf)));
+   goto out_delete_evlist;
+   }
+   top.evlist->env = _env;
 
argc = parse_options(argc, argv, options, top_usage, 0);
if (argc)


[tip: perf/core] perf tools: Avoid 'sample_reg_masks' being const + weak

2019-10-14 Thread tip-bot2 for Ian Rogers
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 42466b9f29b415c254dc4c2f4618e2a96951a406
Gitweb:
https://git.kernel.org/tip/42466b9f29b415c254dc4c2f4618e2a96951a406
Author:Ian Rogers 
AuthorDate:Mon, 30 Sep 2019 17:36:23 -07:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 09:29:33 -03:00

perf tools: Avoid 'sample_reg_masks' being const + weak

Being const + weak breaks with some compilers that constant-propagate
from the weak symbol. This behavior is outside of the specification, but
in LLVM is chosen to match GCC's behavior.

LLVM's implementation was set in this patch:

  
https://github.com/llvm/llvm-project/commit/f49573d1eedcf1e44893d5a062ac1b72c8419646

A const + weak symbol is set to be weak_odr:

  https://llvm.org/docs/LangRef.html

ODR is one definition rule, and given there is one constant definition
constant-propagation is possible. It is possible to get this code to
miscompile with LLVM when applying link time optimization. As compilers
become more aggressive, this is likely to break in more instances.

Move the definition of sample_reg_masks to the conditional part of
perf_regs.h and guard usage with HAVE_PERF_REGS_SUPPORT. This avoids the
weak symbol.

Fix an issue when HAVE_PERF_REGS_SUPPORT isn't defined from patch v1.
In v3, add perf_regs.c for architectures that HAVE_PERF_REGS_SUPPORT but
don't declare sample_regs_masks.

Further notes:

Jiri asked:

  "Is this just a precaution or you actualy saw some breakage?"

Ian answered:

  "We saw a breakage with clang with thinlto enabled for linking. Our
   compiler team had recently seen, and were surprised by, a similar issue
   and were able to dig out the weak ODR issue."

Signed-off-by: Ian Rogers 
Reviewed-by: Nick Desaulniers 
Acked-by: Jiri Olsa 
Cc: Albert Ou 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: clang-built-li...@googlegroups.com
Cc: Guo Ren 
Cc: Kan Liang 
Cc: linux-ri...@lists.infradead.org
Cc: Mao Han 
Cc: Mark Rutland 
Cc: Namhyung Kim 
Cc: Palmer Dabbelt 
Cc: Paul Walmsley 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lore.kernel.org/lkml/20191001003623.255186-1-irog...@google.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/Build | 2 ++
 tools/perf/arch/arm/util/perf_regs.c   | 6 ++
 tools/perf/arch/arm64/util/Build   | 1 +
 tools/perf/arch/arm64/util/perf_regs.c | 6 ++
 tools/perf/arch/csky/util/Build| 2 ++
 tools/perf/arch/csky/util/perf_regs.c  | 6 ++
 tools/perf/arch/riscv/util/Build   | 2 ++
 tools/perf/arch/riscv/util/perf_regs.c | 6 ++
 tools/perf/arch/s390/util/Build| 1 +
 tools/perf/arch/s390/util/perf_regs.c  | 6 ++
 tools/perf/util/parse-regs-options.c   | 8 ++--
 tools/perf/util/perf_regs.c| 4 
 tools/perf/util/perf_regs.h| 4 ++--
 13 files changed, 46 insertions(+), 8 deletions(-)
 create mode 100644 tools/perf/arch/arm/util/perf_regs.c
 create mode 100644 tools/perf/arch/arm64/util/perf_regs.c
 create mode 100644 tools/perf/arch/csky/util/perf_regs.c
 create mode 100644 tools/perf/arch/riscv/util/perf_regs.c
 create mode 100644 tools/perf/arch/s390/util/perf_regs.c

diff --git a/tools/perf/arch/arm/util/Build b/tools/perf/arch/arm/util/Build
index 296f0ea..37fc637 100644
--- a/tools/perf/arch/arm/util/Build
+++ b/tools/perf/arch/arm/util/Build
@@ -1,3 +1,5 @@
+perf-y += perf_regs.o
+
 perf-$(CONFIG_DWARF) += dwarf-regs.o
 
 perf-$(CONFIG_LOCAL_LIBUNWIND)+= unwind-libunwind.o
diff --git a/tools/perf/arch/arm/util/perf_regs.c 
b/tools/perf/arch/arm/util/perf_regs.c
new file mode 100644
index 000..2864e2e
--- /dev/null
+++ b/tools/perf/arch/arm/util/perf_regs.c
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "../../util/perf_regs.h"
+
+const struct sample_reg sample_reg_masks[] = {
+   SMPL_REG_END
+};
diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build
index 3cde540..0a7782c 100644
--- a/tools/perf/arch/arm64/util/Build
+++ b/tools/perf/arch/arm64/util/Build
@@ -1,4 +1,5 @@
 perf-y += header.o
+perf-y += perf_regs.o
 perf-y += sym-handling.o
 perf-$(CONFIG_DWARF) += dwarf-regs.o
 perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
diff --git a/tools/perf/arch/arm64/util/perf_regs.c 
b/tools/perf/arch/arm64/util/perf_regs.c
new file mode 100644
index 000..2864e2e
--- /dev/null
+++ b/tools/perf/arch/arm64/util/perf_regs.c
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "../../util/perf_regs.h"
+
+const struct sample_reg sample_reg_masks[] = {
+   SMPL_REG_END
+};
diff --git a/tools/perf/arch/csky/util/Build b/tools/perf/arch/csky/util/Build
index 1160bb2..7d30501 100644
--- a/tools/perf/arch/csky/util/Build
+++ b/tools/perf/arch/csky/util/Build
@@ -1,2 +1,4 @@
+perf-y += perf_regs.o
+
 perf-$(CONFIG_DWARF) += dwarf-regs.o
 perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
diff --git 

[tip: perf/core] perf beauty: Make strarray's offset be u64

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 8d6505bae391e640aaefd182907e7c1d673af17e
Gitweb:
https://git.kernel.org/tip/8d6505bae391e640aaefd182907e7c1d673af17e
Author:Arnaldo Carvalho de Melo 
AuthorDate:Wed, 09 Oct 2019 11:22:43 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf beauty: Make strarray's offset be u64

We need it for things like MSRs that are sparse and go over MAXINT.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-g8t2d0jr0mg3yimg2qrjk...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/trace/beauty/beauty.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 4cc4f6b..5ad7542 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -7,7 +7,7 @@
 #include 
 
 struct strarray {
-   int offset;
+   u64 offset;
int nr_entries;
const char *prefix;
const char **entries;


[tip: perf/core] perf evlist: Introduce append_tp_filter_pid() and append_tp_filter_pids()

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 1827ab5ba8e1d0354cc36b3692444306ced01471
Gitweb:
https://git.kernel.org/tip/1827ab5ba8e1d0354cc36b3692444306ced01471
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 07 Oct 2019 17:00:34 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf evlist: Introduce append_tp_filter_pid() and append_tp_filter_pids()

We'll need this to support 'perf trace e tracepoint --filter=expr', as
the command line tracepoint filter is attache to the preceding evsel,
just like in 'perf record' and when we go to set pid filters, which we
do at the minimum to filter 'perf trace' own syscalls, we need to
append, not set the tp filter.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-daynpknni44ywuzi8iua5...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 14 ++
 tools/perf/util/evlist.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 1650d24..e33b46a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1128,6 +1128,20 @@ int perf_evlist__set_tp_filter_pid(struct evlist 
*evlist, pid_t pid)
return perf_evlist__set_tp_filter_pids(evlist, 1, );
 }
 
+int perf_evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, 
pid_t *pids)
+{
+   char *filter = asprintf__tp_filter_pids(npids, pids);
+   int ret = perf_evlist__append_tp_filter(evlist, filter);
+
+   free(filter);
+   return ret;
+}
+
+int perf_evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid)
+{
+   return perf_evlist__append_tp_filter_pids(evlist, 1, );
+}
+
 bool perf_evlist__valid_sample_type(struct evlist *evlist)
 {
struct evsel *pos;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index c58fd19..1305140 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -142,6 +142,9 @@ int perf_evlist__set_tp_filter_pids(struct evlist *evlist, 
size_t npids, pid_t *
 
 int perf_evlist__append_tp_filter(struct evlist *evlist, const char *filter);
 
+int perf_evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
+int perf_evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, 
pid_t *pids);
+
 struct evsel *
 perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
 


[tip: perf/core] perf tools: Make usage of test_attr__* optional for perf-sys.h

2019-10-14 Thread tip-bot2 for Björn Töpel
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 06f84d1989b7e58d56fa2e448664585749d41221
Gitweb:
https://git.kernel.org/tip/06f84d1989b7e58d56fa2e448664585749d41221
Author:Björn Töpel 
AuthorDate:Tue, 01 Oct 2019 13:33:06 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf tools: Make usage of test_attr__* optional for perf-sys.h

For users of perf-sys.h outside perf, e.g. samples/bpf/bpf_load.c, it's
convenient not to depend on test_attr__*.

After commit 91854f9a077e ("perf tools: Move everything related to
sys_perf_event_open() to perf-sys.h"), all users of perf-sys.h will
depend on test_attr__enabled and test_attr__open.

This commit enables a user to define HAVE_ATTR_TEST to zero in order
to omit the test dependency.

Fixes: 91854f9a077e ("perf tools: Move everything related to 
sys_perf_event_open() to perf-sys.h")
Signed-off-by: Björn Töpel 
Acked-by: Song Liu 
Cc: Adrian Hunter 
Cc: Alexei Starovoitov 
Cc: Daniel Borkmann 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: b...@vger.kernel.org
Cc: net...@vger.kernel.org
Link: http://lore.kernel.org/lkml/20191001113307.27796-2-bjorn.to...@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/perf-sys.h | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 63e4349..15e458e 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -15,7 +15,9 @@ void test_attr__init(void);
 void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
 int fd, int group_fd, unsigned long flags);
 
-#define HAVE_ATTR_TEST
+#ifndef HAVE_ATTR_TEST
+#define HAVE_ATTR_TEST 1
+#endif
 
 static inline int
 sys_perf_event_open(struct perf_event_attr *attr,
@@ -27,7 +29,7 @@ sys_perf_event_open(struct perf_event_attr *attr,
fd = syscall(__NR_perf_event_open, attr, pid, cpu,
 group_fd, flags);
 
-#ifdef HAVE_ATTR_TEST
+#if HAVE_ATTR_TEST
if (unlikely(test_attr__enabled))
test_attr__open(attr, pid, cpu, fd, group_fd, flags);
 #endif


[tip: perf/core] perf scripts python: exported-sql-viewer.py: Add Time chart by CPU

2019-10-14 Thread tip-bot2 for Adrian Hunter
The following commit has been merged into the perf/core branch of tip:

Commit-ID: b3700f21c2ede55aeab3aba728bce434051ec631
Gitweb:
https://git.kernel.org/tip/b3700f21c2ede55aeab3aba728bce434051ec631
Author:Adrian Hunter 
AuthorDate:Wed, 21 Aug 2019 11:32:16 +03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf scripts python: exported-sql-viewer.py: Add Time chart by CPU

Add a time chart based on context switch information.

Context switch information was added to the database export fairly
recently, so the chart menu option will only appear if context switch
information is in the database.

Refer to the Exported SQL Viewer Help option for more information about
the chart.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lore.kernel.org/lkml/20190821083216.1340-7-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/exported-sql-viewer.py | 1333 -
 1 file changed, 1331 insertions(+), 2 deletions(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index a5af52f..ebc6a2e 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -105,6 +105,9 @@ except ImportError:
glb_nsz = 16
 import re
 import os
+import random
+import copy
+import math
 
 pyside_version_1 = True
 if not "--pyside-version-1" in sys.argv:
@@ -1154,6 +1157,1301 @@ class CallTreeWindow(TreeWindowBase):
self.view.setCurrentIndex(last_child)
parent = last_child
 
+# ExecComm() gets the comm_id of the command string that was set when the 
process exec'd i.e. the program name
+
+def ExecComm(db, thread_id, time):
+   query = QSqlQuery(db)
+   QueryExec(query, "SELECT comm_threads.comm_id, comms.c_time, 
comms.exec_flag"
+   " FROM comm_threads"
+   " INNER JOIN comms ON comms.id = 
comm_threads.comm_id"
+   " WHERE comm_threads.thread_id = " + 
str(thread_id) +
+   " ORDER BY comms.c_time, comms.id")
+   first = None
+   last = None
+   while query.next():
+   if first is None:
+   first = query.value(0)
+   if query.value(2) and Decimal(query.value(1)) <= Decimal(time):
+   last = query.value(0)
+   if not(last is None):
+   return last
+   return first
+
+# Container for (x, y) data
+
+class XY():
+   def __init__(self, x=0, y=0):
+   self.x = x
+   self.y = y
+
+   def __str__(self):
+   return "XY({}, {})".format(str(self.x), str(self.y))
+
+# Container for sub-range data
+
+class Subrange():
+   def __init__(self, lo=0, hi=0):
+   self.lo = lo
+   self.hi = hi
+
+   def __str__(self):
+   return "Subrange({}, {})".format(str(self.lo), str(self.hi))
+
+# Graph data region base class
+
+class GraphDataRegion(object):
+
+   def __init__(self, key, title = "", ordinal = ""):
+   self.key = key
+   self.title = title
+   self.ordinal = ordinal
+
+# Function to sort GraphDataRegion
+
+def GraphDataRegionOrdinal(data_region):
+   return data_region.ordinal
+
+# Attributes for a graph region
+
+class GraphRegionAttribute():
+
+   def __init__(self, colour):
+   self.colour = colour
+
+# Switch graph data region represents a task
+
+class SwitchGraphDataRegion(GraphDataRegion):
+
+   def __init__(self, key, exec_comm_id, pid, tid, comm, thread_id, 
comm_id):
+   super(SwitchGraphDataRegion, self).__init__(key)
+
+   self.title = str(pid) + " / " + str(tid) + " " + comm
+   # Order graph legend within exec comm by pid / tid / time
+   self.ordinal = str(pid).rjust(16) + str(exec_comm_id).rjust(8) 
+ str(tid).rjust(16)
+   self.exec_comm_id = exec_comm_id
+   self.pid = pid
+   self.tid = tid
+   self.comm = comm
+   self.thread_id = thread_id
+   self.comm_id = comm_id
+
+# Graph data point
+
+class GraphDataPoint():
+
+   def __init__(self, data, index, x, y, altx=None, alty=None, 
hregion=None, vregion=None):
+   self.data = data
+   self.index = index
+   self.x = x
+   self.y = y
+   self.altx = altx
+   self.alty = alty
+   self.hregion = hregion
+   self.vregion = vregion
+
+# Graph data (single graph) base class
+
+class GraphData(object):
+
+   def __init__(self, collection, xbase=Decimal(0), ybase=Decimal(0)):
+   self.collection = collection
+   self.points = []
+   self.xbase = xbase
+   

[tip: perf/core] perf scripts python: exported-sql-viewer.py: Add global time range calculations

2019-10-14 Thread tip-bot2 for Adrian Hunter
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 9a9dae36556e8f7689f68f05d169ac6c132c5f15
Gitweb:
https://git.kernel.org/tip/9a9dae36556e8f7689f68f05d169ac6c132c5f15
Author:Adrian Hunter 
AuthorDate:Wed, 21 Aug 2019 11:32:13 +03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf scripts python: exported-sql-viewer.py: Add global time range calculations

Add calculations to determine a time range that encompasses all data.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lore.kernel.org/lkml/20190821083216.1340-4-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/exported-sql-viewer.py | 113 +-
 1 file changed, 109 insertions(+), 4 deletions(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index 9767a5f..0dcc9a0 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -2088,10 +2088,8 @@ class SampleTimeRangesDataItem(LineEditDataItem):
QueryExec(query, "SELECT id, time FROM samples ORDER BY id DESC 
LIMIT 1")
if query.next():
self.last_id = int(query.value(0))
-   self.last_time = int(query.value(1))
-   QueryExec(query, "SELECT time FROM samples WHERE time != 0 
ORDER BY id LIMIT 1")
-   if query.next():
-   self.first_time = int(query.value(0))
+   self.first_time = int(glb.HostStartTime())
+   self.last_time = int(glb.HostFinishTime())
if placeholder_text:
placeholder_text += ", between " + str(self.first_time) 
+ " and " + str(self.last_time)
 
@@ -3500,6 +3498,9 @@ class Glb():
self.have_disassembler = True
except:
self.have_disassembler = False
+   self.host_machine_id = 0
+   self.host_start_time = 0
+   self.host_finish_time = 0
 
def FileFromBuildId(self, build_id):
file_name = self.buildid_dir + build_id[0:2] + "/" + 
build_id[2:] + "/elf"
@@ -3532,6 +3533,110 @@ class Glb():
except:
pass
 
+   def GetHostMachineId(self):
+   query = QSqlQuery(self.db)
+   QueryExec(query, "SELECT id FROM machines WHERE pid = -1")
+   if query.next():
+   self.host_machine_id = query.value(0)
+   else:
+   self.host_machine_id = 0
+   return self.host_machine_id
+
+   def HostMachineId(self):
+   if self.host_machine_id:
+   return self.host_machine_id
+   return self.GetHostMachineId()
+
+   def SelectValue(self, sql):
+   query = QSqlQuery(self.db)
+   try:
+   QueryExec(query, sql)
+   except:
+   return None
+   if query.next():
+   return Decimal(query.value(0))
+   return None
+
+   def SwitchesMinTime(self, machine_id):
+   return self.SelectValue("SELECT time"
+   " FROM context_switches"
+   " WHERE time != 0 AND machine_id = " + 
str(machine_id) +
+   " ORDER BY id LIMIT 1")
+
+   def SwitchesMaxTime(self, machine_id):
+   return self.SelectValue("SELECT time"
+   " FROM context_switches"
+   " WHERE time != 0 AND machine_id = " + 
str(machine_id) +
+   " ORDER BY id DESC LIMIT 1")
+
+   def SamplesMinTime(self, machine_id):
+   return self.SelectValue("SELECT time"
+   " FROM samples"
+   " WHERE time != 0 AND machine_id = " + 
str(machine_id) +
+   " ORDER BY id LIMIT 1")
+
+   def SamplesMaxTime(self, machine_id):
+   return self.SelectValue("SELECT time"
+   " FROM samples"
+   " WHERE time != 0 AND machine_id = " + 
str(machine_id) +
+   " ORDER BY id DESC LIMIT 1")
+
+   def CallsMinTime(self, machine_id):
+   return self.SelectValue("SELECT calls.call_time"
+   " FROM calls"
+   " INNER JOIN threads ON 
threads.thread_id = calls.thread_id"
+   " WHERE calls.call_time != 0 AND 
threads.machine_id = " + str(machine_id) +
+   " 

[tip: perf/core] perf scripts python: exported-sql-viewer.py: Add HBoxLayout and VBoxLayout

2019-10-14 Thread tip-bot2 for Adrian Hunter
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 42c303ff9a25c4b95a75f8f10d08661183497d41
Gitweb:
https://git.kernel.org/tip/42c303ff9a25c4b95a75f8f10d08661183497d41
Author:Adrian Hunter 
AuthorDate:Wed, 21 Aug 2019 11:32:12 +03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf scripts python: exported-sql-viewer.py: Add HBoxLayout and VBoxLayout

Add layout classes HBoxLayout and VBoxLayout.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lore.kernel.org/lkml/20190821083216.1340-3-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/exported-sql-viewer.py | 41 +++
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index 18ad046..9767a5f 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -980,20 +980,41 @@ class CallTreeModel(CallGraphModelBase):
ids.insert(0, query.value(1))
return ids
 
-# Vertical widget layout
+# Vertical layout
 
-class VBox():
+class HBoxLayout(QHBoxLayout):
 
-   def __init__(self, w1, w2, w3=None):
-   self.vbox = QWidget()
-   self.vbox.setLayout(QVBoxLayout())
+   def __init__(self, *children):
+   super(HBoxLayout, self).__init__()
+
+   self.layout().setContentsMargins(0, 0, 0, 0)
+   for child in children:
+   if child.isWidgetType():
+   self.layout().addWidget(child)
+   else:
+   self.layout().addLayout(child)
+
+# Horizontal layout
+
+class VBoxLayout(QVBoxLayout):
 
-   self.vbox.layout().setContentsMargins(0, 0, 0, 0)
+   def __init__(self, *children):
+   super(VBoxLayout, self).__init__()
 
-   self.vbox.layout().addWidget(w1)
-   self.vbox.layout().addWidget(w2)
-   if w3:
-   self.vbox.layout().addWidget(w3)
+   self.layout().setContentsMargins(0, 0, 0, 0)
+   for child in children:
+   if child.isWidgetType():
+   self.layout().addWidget(child)
+   else:
+   self.layout().addLayout(child)
+
+# Vertical layout widget
+
+class VBox():
+
+   def __init__(self, *children):
+   self.vbox = QWidget()
+   self.vbox.setLayout(VBoxLayout(*children))
 
def Widget(self):
return self.vbox


[tip: perf/core] perf scripts python: exported-sql-viewer.py: Add LookupModel()

2019-10-14 Thread tip-bot2 for Adrian Hunter
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 181ea40a24af9a60c2ee75d4f271980f6453f585
Gitweb:
https://git.kernel.org/tip/181ea40a24af9a60c2ee75d4f271980f6453f585
Author:Adrian Hunter 
AuthorDate:Wed, 21 Aug 2019 11:32:11 +03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf scripts python: exported-sql-viewer.py: Add LookupModel()

Add LookupModel() to find a model in the model cache without creating it.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lore.kernel.org/lkml/20190821083216.1340-2-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/exported-sql-viewer.py |  9 +
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index 61b3911..18ad046 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -341,6 +341,15 @@ def LookupCreateModel(model_name, create_fn):
model_cache_lock.release()
return model
 
+def LookupModel(model_name):
+   model_cache_lock.acquire()
+   try:
+   model = model_cache[model_name]
+   except:
+   model = None
+   model_cache_lock.release()
+   return model
+
 # Find bar
 
 class FindBar():


[tip: perf/core] perf trace: Separate 'struct syscall_fmt' definition from syscall_fmts variable

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 9b2036cd329924082acfa5dec58deec12fa1f5e8
Gitweb:
https://git.kernel.org/tip/9b2036cd329924082acfa5dec58deec12fa1f5e8
Author:Arnaldo Carvalho de Melo 
AuthorDate:Tue, 01 Oct 2019 15:16:33 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf trace: Separate 'struct syscall_fmt' definition from syscall_fmts variable

As this has all the things needed to format tracepoints events, not just
syscalls, that, after all, are just tracepoints with a set in stone ABI,
i.e. order and number of parameters.

For tracepoints we'll create a

  static struct syscall_fmt tracepoint_fmts[]

array and will fill the ->arg[] entries with the beautifier for each
positional argument and record the name, then, when we need it, we'll
just check that the position has the same name, maybe even type, so that
we can do some check that the tracepoint hasn't changed, if it has, we
can even reorder things.

Keep calling it syscall_fmt but use it as well for tracepoints, do it
this way to minimize changes and reuse what is in place for syscalls,
we'll see.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-2x1jgiev13zt4njaanlnn...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index ee330f5..cb85343 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -702,7 +702,7 @@ struct syscall_arg_fmt {
bool   show_zero;
 };
 
-static struct syscall_fmt {
+struct syscall_fmt {
const char *name;
const char *alias;
struct {
@@ -714,7 +714,9 @@ static struct syscall_fmt {
bool   errpid;
bool   timeout;
bool   hexret;
-} syscall_fmts[] = {
+};
+
+static struct syscall_fmt syscall_fmts[] = {
{ .name = "access",
  .arg = { [1] = { .scnprintf = SCA_ACCMODE,  /* mode */ }, }, },
{ .name = "arch_prctl",


[tip: perf/core] perf scripts python: exported-sql-viewer.py: Tidy up Call tree call_time

2019-10-14 Thread tip-bot2 for Adrian Hunter
The following commit has been merged into the perf/core branch of tip:

Commit-ID: da4264f5cf8a6b798bf5494e08a5dae85a61c4c3
Gitweb:
https://git.kernel.org/tip/da4264f5cf8a6b798bf5494e08a5dae85a61c4c3
Author:Adrian Hunter 
AuthorDate:Wed, 21 Aug 2019 11:32:14 +03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:17 -03:00

perf scripts python: exported-sql-viewer.py: Tidy up Call tree call_time

Record call_time on tree nodes and re-name the misnamed "count" parameter.

Signed-off-by: Adrian Hunter 
Cc: Jiri Olsa 
Link: http://lore.kernel.org/lkml/20190821083216.1340-5-adrian.hun...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/exported-sql-viewer.py | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index 0dcc9a0..06b8d55 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -794,15 +794,16 @@ class CallGraphModel(CallGraphModelBase):
 
 class CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
 
-   def __init__(self, glb, params, row, comm_id, thread_id, calls_id, 
time, insn_cnt, cyc_cnt, branch_count, parent_item):
+   def __init__(self, glb, params, row, comm_id, thread_id, calls_id, 
call_time, time, insn_cnt, cyc_cnt, branch_count, parent_item):
super(CallTreeLevelTwoPlusItemBase, self).__init__(glb, params, 
row, parent_item)
self.comm_id = comm_id
self.thread_id = thread_id
self.calls_id = calls_id
+   self.call_time = call_time
+   self.time = time
self.insn_cnt = insn_cnt
self.cyc_cnt = cyc_cnt
self.branch_count = branch_count
-   self.time = time
 
def Select(self):
self.query_done = True
@@ -839,17 +840,17 @@ class 
CallTreeLevelTwoPlusItemBase(CallGraphLevelItemBase):
 
 class CallTreeLevelThreeItem(CallTreeLevelTwoPlusItemBase):
 
-   def __init__(self, glb, params, row, comm_id, thread_id, calls_id, 
name, dso, count, time, insn_cnt, cyc_cnt, branch_count, parent_item):
-   super(CallTreeLevelThreeItem, self).__init__(glb, params, row, 
comm_id, thread_id, calls_id, time, insn_cnt, cyc_cnt, branch_count, 
parent_item)
+   def __init__(self, glb, params, row, comm_id, thread_id, calls_id, 
name, dso, call_time, time, insn_cnt, cyc_cnt, branch_count, parent_item):
+   super(CallTreeLevelThreeItem, self).__init__(glb, params, row, 
comm_id, thread_id, calls_id, call_time, time, insn_cnt, cyc_cnt, branch_count, 
parent_item)
dso = dsoname(dso)
if self.params.have_ipc:
insn_pcnt = PercentToOneDP(insn_cnt, 
parent_item.insn_cnt)
cyc_pcnt = PercentToOneDP(cyc_cnt, parent_item.cyc_cnt)
br_pcnt = PercentToOneDP(branch_count, 
parent_item.branch_count)
ipc = CalcIPC(cyc_cnt, insn_cnt)
-   self.data = [ name, dso, str(count), str(time), 
PercentToOneDP(time, parent_item.time), str(insn_cnt), insn_pcnt, str(cyc_cnt), 
cyc_pcnt, ipc, str(branch_count), br_pcnt ]
+   self.data = [ name, dso, str(call_time), str(time), 
PercentToOneDP(time, parent_item.time), str(insn_cnt), insn_pcnt, str(cyc_cnt), 
cyc_pcnt, ipc, str(branch_count), br_pcnt ]
else:
-   self.data = [ name, dso, str(count), str(time), 
PercentToOneDP(time, parent_item.time), str(branch_count), 
PercentToOneDP(branch_count, parent_item.branch_count) ]
+   self.data = [ name, dso, str(call_time), str(time), 
PercentToOneDP(time, parent_item.time), str(branch_count), 
PercentToOneDP(branch_count, parent_item.branch_count) ]
self.dbid = calls_id
 
 # Call tree data model level two item
@@ -857,7 +858,7 @@ class CallTreeLevelThreeItem(CallTreeLevelTwoPlusItemBase):
 class CallTreeLevelTwoItem(CallTreeLevelTwoPlusItemBase):
 
def __init__(self, glb, params, row, comm_id, thread_id, pid, tid, 
parent_item):
-   super(CallTreeLevelTwoItem, self).__init__(glb, params, row, 
comm_id, thread_id, 0, 0, 0, 0, 0, parent_item)
+   super(CallTreeLevelTwoItem, self).__init__(glb, params, row, 
comm_id, thread_id, 0, 0, 0, 0, 0, 0, parent_item)
if self.params.have_ipc:
self.data = [str(pid) + ":" + str(tid), "", "", "", "", 
"", "", "", "", "", "", ""]
else:


[tip: perf/core] MAINTAINERS: Add entry for perf tool arm64 pmu-events files

2019-10-14 Thread tip-bot2 for John Garry
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 26d5310ee28ad9395bd676f750d2ee3ddff3dcfd
Gitweb:
https://git.kernel.org/tip/26d5310ee28ad9395bd676f750d2ee3ddff3dcfd
Author:John Garry 
AuthorDate:Wed, 09 Oct 2019 16:54:33 +08:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 09:35:12 -03:00

MAINTAINERS: Add entry for perf tool arm64 pmu-events files

Will and I have an interest in reviewing the pmu-events changes related
to arm64, so add a specific entry for this.

Signed-off-by: John Garry 
Cc: Alexander Shishkin 
Cc: Florian Fainelli 
Cc: Jiri Olsa 
Cc: linux...@huawei.com
Cc: linux-arm-ker...@lists.infradead.org
Cc: Mark Rutland 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Shaokun Zhang 
Cc: Will Deacon 
Link: 
http://lore.kernel.org/lkml/1570611273-108281-1-git-send-email-john.ga...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 55199ef..b50ddc8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12771,6 +12771,13 @@ F: arch/*/events/*
 F: arch/*/events/*/*
 F: tools/perf/
 
+PERFORMANCE EVENTS SUBSYSTEM ARM64 PMU EVENTS
+R: John Garry 
+R: Will Deacon 
+L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
+S: Supported
+F: tools/perf/pmu-events/arch/arm64/
+
 PERSONALITY HANDLING
 M: Christoph Hellwig 
 L: linux-abi-de...@lists.sourceforge.net


[tip: perf/core] perf trace: Factor out the initialization of syscal_arg_fmt->scnprintf

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 8d1d4ff5e239d9ef385444bc0d855127d7b32754
Gitweb:
https://git.kernel.org/tip/8d1d4ff5e239d9ef385444bc0d855127d7b32754
Author:Arnaldo Carvalho de Melo 
AuthorDate:Thu, 03 Oct 2019 15:57:42 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf trace: Factor out the initialization of syscal_arg_fmt->scnprintf

We set the default scnprint routines for the syscall args based on its
type or on heuristics based on its names, now we'll use this for
tracepoints as well, so move it out of syscall__set_arg_fmts() and into
a routine that receive just an array of syscall_arg_fmt entries + the
tracepoint format fields list.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-xs3x0zzyes06c7scdsjn0...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6c70253..d52dd2b 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1467,15 +1467,16 @@ static int syscall__alloc_arg_fmts(struct syscall *sc, 
int nr_args)
return 0;
 }
 
-static int syscall__set_arg_fmts(struct syscall *sc)
+static struct tep_format_field *
+syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, struct 
tep_format_field *field)
 {
-   struct tep_format_field *field, *last_field = NULL;
-   int idx = 0, len;
+   struct tep_format_field *last_field = NULL;
+   int len;
 
-   for (field = sc->args; field; field = field->next, ++idx) {
+   for (; field; field = field->next, ++arg) {
last_field = field;
 
-   if (sc->fmt && sc->fmt->arg[idx].scnprintf)
+   if (arg->scnprintf)
continue;
 
len = strlen(field->name);
@@ -1483,13 +1484,13 @@ static int syscall__set_arg_fmts(struct syscall *sc)
if (strcmp(field->type, "const char *") == 0 &&
((len >= 4 && strcmp(field->name + len - 4, "name") == 0) ||
 strstr(field->name, "path") != NULL))
-   sc->arg_fmt[idx].scnprintf = SCA_FILENAME;
+   arg->scnprintf = SCA_FILENAME;
else if ((field->flags & TEP_FIELD_IS_POINTER) || 
strstr(field->name, "addr"))
-   sc->arg_fmt[idx].scnprintf = SCA_PTR;
+   arg->scnprintf = SCA_PTR;
else if (strcmp(field->type, "pid_t") == 0)
-   sc->arg_fmt[idx].scnprintf = SCA_PID;
+   arg->scnprintf = SCA_PID;
else if (strcmp(field->type, "umode_t") == 0)
-   sc->arg_fmt[idx].scnprintf = SCA_MODE_T;
+   arg->scnprintf = SCA_MODE_T;
else if ((strcmp(field->type, "int") == 0 ||
  strcmp(field->type, "unsigned int") == 0 ||
  strcmp(field->type, "long") == 0) &&
@@ -1501,10 +1502,17 @@ static int syscall__set_arg_fmts(struct syscall *sc)
 * 23 unsigned int
 * 7 unsigned long
 */
-   sc->arg_fmt[idx].scnprintf = SCA_FD;
+   arg->scnprintf = SCA_FD;
}
}
 
+   return last_field;
+}
+
+static int syscall__set_arg_fmts(struct syscall *sc)
+{
+   struct tep_format_field *last_field = 
syscall_arg_fmt__init_array(sc->arg_fmt, sc->args);
+
if (last_field)
sc->args_size = last_field->offset + last_field->size;
 


[tip: perf/core] perf trace: Allow choosing how to augment the tracepoint arguments

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: f11b2803bb88655d90b88c787710b53100913bff
Gitweb:
https://git.kernel.org/tip/f11b2803bb88655d90b88c787710b53100913bff
Author:Arnaldo Carvalho de Melo 
AuthorDate:Fri, 04 Oct 2019 15:28:13 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf trace: Allow choosing how to augment the tracepoint arguments

So far we used the libtraceevent printing routines when showing
tracepoint arguments, but since 'perf trace' has a lot of beautifiers
for syscall arguments, and since some of those can be used to augment
tracepoint arguments, add a routine to make use of those beautifiers
and allow the user to choose which one to use.

The default now is to use the same beautifiers used for the strace-like
sys_enter+sys_exit lines, but the user can choose the libtraceevent ones
by either using the:

perf trace --libtraceevent_print

command line option, or by setting:

  # cat ~/.perfconfig
  [trace]
tracepoint_beautifiers = libtraceevent

For instance, here are some examples:

  # perf trace -e sched:*switch,*sleep,sched:*wakeup,exit*,sched:*exit sleep 1
   0.000 sched:sched_wakeup(comm: "perf", pid: 5273 (perf), prio: 120, 
success: 1, target_cpu: 6)
   0.621 nanosleep(rqtp: 0x7ffdd06d1140, rmtp: NULL) ...
   0.628 sched:sched_switch(prev_comm: "sleep", prev_pid: 5273 (sleep), 
prev_prio: 120, prev_state: 1, next_comm: "swapper/6", next_pid: 0, next_prio: 
120)
1000.879 sched:sched_wakeup(comm: "sleep", pid: 5273 (sleep), prio: 120, 
success: 1, target_cpu: 6)
   0.621  ... [continued]: nanosleep())  = 0
1001.026 exit_group(error_code: 0)   = ?
1001.216 sched:sched_process_exit(comm: "sleep", pid: 5273 (sleep), prio: 
120)
  #

And then using libtraceevent, as before:

  # perf trace --libtraceevent_print -e 
sched:*switch,*sleep,sched:*wakeup,exit*,sched:*exit sleep 1
   0.000 sched:sched_wakeup(comm=perf pid=5288 prio=120 target_cpu=001)
   0.739 nanosleep(rqtp: 0x7ffeba6c2f40, rmtp: NULL) ...
   0.747 sched:sched_switch(prev_comm=sleep prev_pid=5288 prev_prio=120 
prev_state=S ==> next_comm=swapper/1 next_pid=0 next_prio=120)
1000.902 sched:sched_wakeup(comm=sleep pid=5288 prio=120 target_cpu=001)
   0.739  ... [continued]: nanosleep())  = 0
1001.012 exit_group(error_code: 0)   = ?
  #

The new default allocates an array of 'struct syscall_arg_fmt' for the
tracepoint arguments and, just like with syscall arguments, tries to
find suitable syscall_arg__scnprintf_NAME() routines to augment those
tracepoint arguments based on their type (as in the tracefs "format"
file), or even in their name + type, for instance arguntents with names
ending in "fd" with type "int" get the fd scnprintf beautifier attached,
etc.

Soon this will take advantage of the kernel BTF information to augment
enumerations based on the tracefs "format" type info.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-o8qdluotkcb3b1x2gjqre...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-config.txt |  5 +-
 tools/perf/Documentation/perf-trace.txt  |  5 +-
 tools/perf/builtin-trace.c   | 83 ++-
 3 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-config.txt 
b/tools/perf/Documentation/perf-config.txt
index c599623..c4dd23c 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -561,6 +561,11 @@ trace.*::
trace.show_zeros::
Do not suppress syscall arguments that are equal to zero.
 
+   trace.tracepoint_beautifiers::
+   Use "libtraceevent" to use that library to augment the 
tracepoint arguments,
+   "libbeauty", the default, to use the same argument beautifiers 
used in the
+   strace-like sys_enter+sys_exit lines.
+
 llvm.*::
llvm.clang-path::
Path to clang. If omit, search it from $PATH.
diff --git a/tools/perf/Documentation/perf-trace.txt 
b/tools/perf/Documentation/perf-trace.txt
index 25b74fd..ba16cd5 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -219,6 +219,11 @@ the thread executes on the designated CPUs. Default is to 
monitor all CPUs.
may happen, for instance, when a thread gets migrated to a different CPU
while processing a syscall.
 
+--libtraceevent_print::
+   Use libtraceevent to print tracepoint arguments. By default 'perf 
trace' uses
+   the same beautifiers used in the strace-like enter+exit lines to 
augment the
+   tracepoint arguments.
+
 --map-dump::
Dump BPF maps setup by events passed via -e, for instance the 
augmented_raw_syscalls
living in 

[tip: perf/core] perf trace: Add the syscall_arg_fmt pointer to syscall_arg

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 888ca854e275fcfbb13206d32bb01c0576fc5546
Gitweb:
https://git.kernel.org/tip/888ca854e275fcfbb13206d32bb01c0576fc5546
Author:Arnaldo Carvalho de Melo 
AuthorDate:Fri, 04 Oct 2019 14:52:30 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Mon, 07 Oct 2019 12:22:18 -03:00

perf trace: Add the syscall_arg_fmt pointer to syscall_arg

So that the scnprintf beautifiers can access it, as will be the case
with the char array one in the following csets, that needs to know
the number of elements in an array.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Luis Cláudio Gonçalves 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-01qmjqv6cb1nj1qy4khde...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c   | 45 +++
 tools/perf/trace/beauty/beauty.h |  3 ++-
 2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 82d39ef..f30296c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -86,6 +86,28 @@
 # define F_LINUX_SPECIFIC_BASE 1024
 #endif
 
+struct syscall_arg_fmt {
+   size_t (*scnprintf)(char *bf, size_t size, struct syscall_arg *arg);
+   unsigned long (*mask_val)(struct syscall_arg *arg, unsigned long val);
+   void   *parm;
+   const char *name;
+   bool   show_zero;
+};
+
+struct syscall_fmt {
+   const char *name;
+   const char *alias;
+   struct {
+   const char *sys_enter,
+  *sys_exit;
+   }  bpf_prog_name;
+   struct syscall_arg_fmt arg[6];
+   u8 nr_args;
+   bool   errpid;
+   bool   timeout;
+   bool   hexret;
+};
+
 struct trace {
struct perf_tooltool;
struct syscalltbl   *sctbl;
@@ -695,28 +717,6 @@ static size_t syscall_arg__scnprintf_getrandom_flags(char 
*bf, size_t size,
 #include "trace/beauty/socket_type.c"
 #include "trace/beauty/waitid_options.c"
 
-struct syscall_arg_fmt {
-   size_t (*scnprintf)(char *bf, size_t size, struct syscall_arg *arg);
-   unsigned long (*mask_val)(struct syscall_arg *arg, unsigned long val);
-   void   *parm;
-   const char *name;
-   bool   show_zero;
-};
-
-struct syscall_fmt {
-   const char *name;
-   const char *alias;
-   struct {
-   const char *sys_enter,
-  *sys_exit;
-   }  bpf_prog_name;
-   struct syscall_arg_fmt arg[6];
-   u8 nr_args;
-   bool   errpid;
-   bool   timeout;
-   bool   hexret;
-};
-
 static struct syscall_fmt syscall_fmts[] = {
{ .name = "access",
  .arg = { [1] = { .scnprintf = SCA_ACCMODE,  /* mode */ }, }, },
@@ -1771,6 +1771,7 @@ static size_t syscall__scnprintf_args(struct syscall *sc, 
char *bf, size_t size,
if (arg.mask & bit)
continue;
 
+   arg.fmt = >arg_fmt[arg.idx];
val = syscall_arg__val(, arg.idx);
/*
 * Some syscall args need some mask, most don't and
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 7e06605..4cc4f6b 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -78,6 +78,8 @@ struct augmented_arg {
u64  value[];
 };
 
+struct syscall_arg_fmt;
+
 /**
  * @val: value of syscall argument being formatted
  * @args: All the args, use syscall_args__val(arg, nth) to access one
@@ -94,6 +96,7 @@ struct augmented_arg {
 struct syscall_arg {
unsigned long val;
unsigned char *args;
+   struct syscall_arg_fmt *fmt;
struct {
struct augmented_arg *args;
int  size;


[tip: perf/core] perf trace: Allow associating scnprintf routines with well known arg names

2019-10-14 Thread tip-bot2 for Arnaldo Carvalho de Melo
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 5d88099bc00dccddf5da18e25e1223f01644f7a2
Gitweb:
https://git.kernel.org/tip/5d88099bc00dccddf5da18e25e1223f01644f7a2
Author:Arnaldo Carvalho de Melo 
AuthorDate:Mon, 07 Oct 2019 15:50:15 -03:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Wed, 09 Oct 2019 11:23:52 -03:00

perf trace: Allow associating scnprintf routines with well known arg names

For instance 'msr' appears in several tracepoints, so we can associate
it with a single scnprintf() routine auto-generated from kernel headers,
as will be done in followup patches.

Start with an empty array of associations.

Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-89ptht6s5fez82lykuwq1...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 8303d83..d52972c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1479,6 +1479,27 @@ static int syscall__alloc_arg_fmts(struct syscall *sc, 
int nr_args)
return 0;
 }
 
+static struct syscall_arg_fmt syscall_arg_fmts__by_name[] = {
+};
+
+static int syscall_arg_fmt__cmp(const void *name, const void *fmtp)
+{
+   const struct syscall_arg_fmt *fmt = fmtp;
+   return strcmp(name, fmt->name);
+}
+
+static struct syscall_arg_fmt *
+__syscall_arg_fmt__find_by_name(struct syscall_arg_fmt *fmts, const int nmemb, 
const char *name)
+{
+   return bsearch(name, fmts, nmemb, sizeof(struct syscall_arg_fmt), 
syscall_arg_fmt__cmp);
+}
+
+static struct syscall_arg_fmt *syscall_arg_fmt__find_by_name(const char *name)
+{
+   const int nmemb = ARRAY_SIZE(syscall_arg_fmts__by_name);
+   return __syscall_arg_fmt__find_by_name(syscall_arg_fmts__by_name, 
nmemb, name);
+}
+
 static struct tep_format_field *
 syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, struct 
tep_format_field *field)
 {
@@ -1518,6 +1539,11 @@ syscall_arg_fmt__init_array(struct syscall_arg_fmt *arg, 
struct tep_format_field
 * 7 unsigned long
 */
arg->scnprintf = SCA_FD;
+   } else {
+   struct syscall_arg_fmt *fmt = 
syscall_arg_fmt__find_by_name(field->name);
+
+   if (fmt)
+   arg->scnprintf = fmt->scnprintf;
}
}
 


[tip: perf/core] libperf: Adopt perf_evlist__filter_pollfd() from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 84227cb11ff4d9815b9b1daf0c1a2bd7e9274c58
Gitweb:
https://git.kernel.org/tip/84227cb11ff4d9815b9b1daf0c1a2bd7e9274c58
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:34 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:58:45 -03:00

libperf: Adopt perf_evlist__filter_pollfd() from tools/perf

Introduce the perf_evlist__filter_pollfd function and export it in the
perf/evlist.h header, so that libperf users can check if the descriptor
is still alive.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-27-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 15 +++
 tools/perf/lib/include/perf/evlist.h |  2 ++
 tools/perf/lib/libperf.map   |  1 +
 tools/perf/util/evlist.c | 12 +---
 4 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 9534ad9..6504561 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -313,6 +313,21 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, 
int fd,
return pos;
 }
 
+static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
+void *arg __maybe_unused)
+{
+   struct perf_mmap *map = fda->priv[fd].ptr;
+
+   if (map)
+   perf_mmap__put(map);
+}
+
+int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short 
revents_and_mask)
+{
+   return fdarray__filter(>pollfd, revents_and_mask,
+  perf_evlist__munmap_filtered, NULL);
+}
+
 int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
 {
return fdarray__poll(>pollfd, timeout);
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index 28b6a12..16f526e 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -32,6 +32,8 @@ LIBPERF_API void perf_evlist__set_maps(struct perf_evlist 
*evlist,
   struct perf_cpu_map *cpus,
   struct perf_thread_map *threads);
 LIBPERF_API int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
+LIBPERF_API int perf_evlist__filter_pollfd(struct perf_evlist *evlist,
+  short revents_and_mask);
 
 LIBPERF_API int perf_evlist__mmap(struct perf_evlist *evlist, int pages);
 LIBPERF_API void perf_evlist__munmap(struct perf_evlist *evlist);
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 5a18fd1..2184aba 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -42,6 +42,7 @@ LIBPERF_0.0.1 {
perf_evlist__poll;
perf_evlist__mmap;
perf_evlist__munmap;
+   perf_evlist__filter_pollfd;
perf_mmap__consume;
perf_mmap__read_init;
perf_mmap__read_done;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 031ace3..21b77ef 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -423,19 +423,9 @@ int evlist__add_pollfd(struct evlist *evlist, int fd)
return perf_evlist__add_pollfd(>core, fd, NULL, POLLIN);
 }
 
-static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
-void *arg __maybe_unused)
-{
-   struct perf_mmap *map = fda->priv[fd].ptr;
-
-   if (map)
-   perf_mmap__put(map);
-}
-
 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
 {
-   return fdarray__filter(>core.pollfd, revents_and_mask,
-  perf_evlist__munmap_filtered, NULL);
+   return perf_evlist__filter_pollfd(>core, revents_and_mask);
 }
 
 int evlist__poll(struct evlist *evlist, int timeout)


[tip: perf/core] libperf: Adopt perf_mmap__unmap() function from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 59d7ea620b58fa7d107834a81528e3098f1c27b0
Gitweb:
https://git.kernel.org/tip/59d7ea620b58fa7d107834a81528e3098f1c27b0
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:14 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 10:05:57 -03:00

libperf: Adopt perf_mmap__unmap() function from tools/perf

Move perf_mmap__unmap() from tools/perf to libperf, to internal header
internal/mmap.h. It will be used in the following patches. And rename
the existing perf's function to mmap__munmap().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-7-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/internal/mmap.h |  1 +
 tools/perf/lib/mmap.c  | 10 ++
 tools/perf/util/evlist.c   |  4 ++--
 tools/perf/util/mmap.c | 11 +++
 tools/perf/util/mmap.h |  2 +-
 5 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/tools/perf/lib/include/internal/mmap.h 
b/tools/perf/lib/include/internal/mmap.h
index 2e68974..5c2ca9a 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -39,6 +39,7 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map);
 void perf_mmap__init(struct perf_mmap *map, bool overwrite);
 int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
int fd, int cpu);
+void perf_mmap__munmap(struct perf_mmap *map);
 void perf_mmap__get(struct perf_mmap *map);
 
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index b765e05..6eb228d 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -32,6 +32,16 @@ int perf_mmap__mmap(struct perf_mmap *map, struct 
perf_mmap_param *mp,
return 0;
 }
 
+void perf_mmap__munmap(struct perf_mmap *map)
+{
+   if (map && map->base != NULL) {
+   munmap(map->base, perf_mmap__mmap_len(map));
+   map->base = NULL;
+   map->fd = -1;
+   refcount_set(>refcnt, 0);
+   }
+}
+
 void perf_mmap__get(struct perf_mmap *map)
 {
refcount_inc(>refcnt);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index dc5b360..0b877d3 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -601,11 +601,11 @@ static void evlist__munmap_nofree(struct evlist *evlist)
 
if (evlist->mmap)
for (i = 0; i < evlist->core.nr_mmaps; i++)
-   perf_mmap__munmap(>mmap[i]);
+   mmap__munmap(>mmap[i]);
 
if (evlist->overwrite_mmap)
for (i = 0; i < evlist->core.nr_mmaps; i++)
-   perf_mmap__munmap(>overwrite_mmap[i]);
+   mmap__munmap(>overwrite_mmap[i]);
 }
 
 void evlist__munmap(struct evlist *evlist)
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index be691b5..2c73b5b 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -115,7 +115,7 @@ void perf_mmap__put(struct mmap *map)
BUG_ON(map->core.base && refcount_read(>core.refcnt) == 0);
 
if (refcount_dec_and_test(>core.refcnt))
-   perf_mmap__munmap(map);
+   mmap__munmap(map);
 }
 
 void perf_mmap__consume(struct mmap *map)
@@ -306,19 +306,14 @@ static void perf_mmap__aio_munmap(struct mmap *map 
__maybe_unused)
 }
 #endif
 
-void perf_mmap__munmap(struct mmap *map)
+void mmap__munmap(struct mmap *map)
 {
+   perf_mmap__munmap(>core);
perf_mmap__aio_munmap(map);
if (map->data != NULL) {
munmap(map->data, mmap__mmap_len(map));
map->data = NULL;
}
-   if (map->core.base != NULL) {
-   munmap(map->core.base, mmap__mmap_len(map));
-   map->core.base = NULL;
-   map->core.fd = -1;
-   refcount_set(>core.refcnt, 0);
-   }
auxtrace_mmap__munmap(>auxtrace_mmap);
 }
 
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index a73402e..6a18b29 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -43,7 +43,7 @@ struct mmap_params {
 };
 
 int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu);
-void perf_mmap__munmap(struct mmap *map);
+void mmap__munmap(struct mmap *map);
 
 void perf_mmap__put(struct mmap *map);
 


[tip: perf/core] libperf: Add 'struct perf_mmap_param'

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: e440979faf6ac8048e1792af383df6af78dd1cb0
Gitweb:
https://git.kernel.org/tip/e440979faf6ac8048e1792af383df6af78dd1cb0
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:10 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 09:40:00 -03:00

libperf: Add 'struct perf_mmap_param'

Add libperf's version of mmap params 'struct perf_mmap_param' object
with the basics: 'prot' and 'mask'.  Encapsulate it in the current
'struct mmap_params' object.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-3-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/internal/mmap.h |  5 +
 tools/perf/util/evlist.c   | 14 +-
 tools/perf/util/mmap.c |  4 ++--
 tools/perf/util/mmap.h |  3 ++-
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/tools/perf/lib/include/internal/mmap.h 
b/tools/perf/lib/include/internal/mmap.h
index e25890d..b26806b 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -29,6 +29,11 @@ struct perf_mmap {
char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8);
 };
 
+struct perf_mmap_param {
+   int prot;
+   int mask;
+};
+
 void perf_mmap__init(struct perf_mmap *map, bool overwrite);
 
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 6c8de08..3a19a7c 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -667,7 +667,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, 
int idx,
int fd;
int cpu;
 
-   mp->prot = PROT_READ | PROT_WRITE;
+   mp->core.prot = PROT_READ | PROT_WRITE;
if (evsel->core.attr.write_backward) {
output = _output_overwrite;
maps = evlist->overwrite_mmap;
@@ -680,7 +680,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, 
int idx,
if (evlist->bkw_mmap_state == BKW_MMAP_NOTREADY)
perf_evlist__toggle_bkw_mmap(evlist, 
BKW_MMAP_RUNNING);
}
-   mp->prot &= ~PROT_WRITE;
+   mp->core.prot &= ~PROT_WRITE;
}
 
if (evsel->core.system_wide && thread)
@@ -921,8 +921,12 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int 
pages,
 * Its value is decided by evsel's write_backward.
 * So  should not be passed through const pointer.
 */
-   struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = 
affinity, .flush = flush,
- .comp_level = comp_level };
+   struct mmap_params mp = {
+   .nr_cblocks = nr_cblocks,
+   .affinity   = affinity,
+   .flush  = flush,
+   .comp_level = comp_level
+   };
 
if (!evlist->mmap)
evlist->mmap = evlist__alloc_mmap(evlist, false);
@@ -934,7 +938,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int 
pages,
 
evlist->core.mmap_len = evlist__mmap_size(pages);
pr_debug("mmap size %zuB\n", evlist->core.mmap_len);
-   mp.mask = evlist->core.mmap_len - page_size - 1;
+   mp.core.mask = evlist->core.mmap_len - page_size - 1;
 
auxtrace_mmap_params__init(_mp, evlist->core.mmap_len,
   auxtrace_pages, auxtrace_overwrite);
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index a35dc57..a496ced 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -370,8 +370,8 @@ int perf_mmap__mmap(struct mmap *map, struct mmap_params 
*mp, int fd, int cpu)
 */
refcount_set(>core.refcnt, 2);
map->core.prev = 0;
-   map->core.mask = mp->mask;
-   map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->prot,
+   map->core.mask = mp->core.mask;
+   map->core.base = mmap(NULL, perf_mmap__mmap_len(map), mp->core.prot,
 MAP_SHARED, fd, 0);
if (map->core.base == MAP_FAILED) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n",
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index e567c1c..4ff75d8 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -37,7 +37,8 @@ struct mmap {
 };
 
 struct mmap_params {
-   int prot, mask, nr_cblocks, affinity, flush, comp_level;
+   struct perf_mmap_param core;
+   int nr_cblocks, affinity, flush, comp_level;
struct auxtrace_mmap_params auxtrace_mp;
 };
 


[tip: perf/core] libperf: Adopt perf_mmap__mmap_len() function from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: bf59b3053e63783520c2810fc3f676553bc7eedd
Gitweb:
https://git.kernel.org/tip/bf59b3053e63783520c2810fc3f676553bc7eedd
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:11 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 09:41:38 -03:00

libperf: Adopt perf_mmap__mmap_len() function from tools/perf

Move perf_mmap__mmap_len() from tools/perf wto libperf, it will be used
in the following patches. And rename the existing perf's function to
mmap__mmap_len().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-4-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c|  4 ++--
 tools/perf/lib/include/internal/mmap.h |  2 ++
 tools/perf/lib/mmap.c  |  6 ++
 tools/perf/util/mmap.c | 20 ++--
 tools/perf/util/mmap.h |  2 +-
 5 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2333286..f05e8b7 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -276,7 +276,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, 
void *buf, size_t size
 
if (record__comp_enabled(aio->rec)) {
size = zstd_compress(aio->rec->session, aio->data + aio->size,
-perf_mmap__mmap_len(map) - aio->size,
+mmap__mmap_len(map) - aio->size,
 buf, size);
} else {
memcpy(aio->data + aio->size, buf, size);
@@ -488,7 +488,7 @@ static int record__pushfn(struct mmap *map, void *to, void 
*bf, size_t size)
struct record *rec = to;
 
if (record__comp_enabled(rec)) {
-   size = zstd_compress(rec->session, map->data, 
perf_mmap__mmap_len(map), bf, size);
+   size = zstd_compress(rec->session, map->data, 
mmap__mmap_len(map), bf, size);
bf   = map->data;
}
 
diff --git a/tools/perf/lib/include/internal/mmap.h 
b/tools/perf/lib/include/internal/mmap.h
index b26806b..e7a6726 100644
--- a/tools/perf/lib/include/internal/mmap.h
+++ b/tools/perf/lib/include/internal/mmap.h
@@ -34,6 +34,8 @@ struct perf_mmap_param {
int mask;
 };
 
+size_t perf_mmap__mmap_len(struct perf_mmap *map);
+
 void perf_mmap__init(struct perf_mmap *map, bool overwrite);
 
 #endif /* __LIBPERF_INTERNAL_MMAP_H */
diff --git a/tools/perf/lib/mmap.c b/tools/perf/lib/mmap.c
index 3da6177..cc4284d 100644
--- a/tools/perf/lib/mmap.c
+++ b/tools/perf/lib/mmap.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
+#include 
 
 void perf_mmap__init(struct perf_mmap *map, bool overwrite)
 {
@@ -7,3 +8,8 @@ void perf_mmap__init(struct perf_mmap *map, bool overwrite)
map->overwrite = overwrite;
refcount_set(>refcnt, 0);
 }
+
+size_t perf_mmap__mmap_len(struct perf_mmap *map)
+{
+   return map->mask + 1 + page_size;
+}
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index a496ced..a8e81c4 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -23,9 +23,9 @@
 #include "../perf.h"
 #include  /* page_size */
 
-size_t perf_mmap__mmap_len(struct mmap *map)
+size_t mmap__mmap_len(struct mmap *map)
 {
-   return map->core.mask + 1 + page_size;
+   return perf_mmap__mmap_len(>core);
 }
 
 /* When check_messup is true, 'end' must points to a good entry */
@@ -170,7 +170,7 @@ static int perf_mmap__aio_enabled(struct mmap *map)
 #ifdef HAVE_LIBNUMA_SUPPORT
 static int perf_mmap__aio_alloc(struct mmap *map, int idx)
 {
-   map->aio.data[idx] = mmap(NULL, perf_mmap__mmap_len(map), 
PROT_READ|PROT_WRITE,
+   map->aio.data[idx] = mmap(NULL, mmap__mmap_len(map), 
PROT_READ|PROT_WRITE,
  MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (map->aio.data[idx] == MAP_FAILED) {
map->aio.data[idx] = NULL;
@@ -183,7 +183,7 @@ static int perf_mmap__aio_alloc(struct mmap *map, int idx)
 static void perf_mmap__aio_free(struct mmap *map, int idx)
 {
if (map->aio.data[idx]) {
-   munmap(map->aio.data[idx], perf_mmap__mmap_len(map));
+   munmap(map->aio.data[idx], mmap__mmap_len(map));
map->aio.data[idx] = NULL;
}
 }
@@ -196,7 +196,7 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, 
int cpu, int affinity)
 
if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) {
data = map->aio.data[idx];
-   mmap_len = perf_mmap__mmap_len(map);
+   mmap_len = mmap__mmap_len(map);
node_mask = 1UL << cpu__get_node(cpu);
if (mbind(data, mmap_len, MPOL_BIND, _mask, 1, 0)) {
 

[tip: perf/core] perf tools: Introduce perf_evlist__mmap_cb_idx()

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 9abd2ab2377613425e1c362694f85b110f5bace2
Gitweb:
https://git.kernel.org/tip/9abd2ab2377613425e1c362694f85b110f5bace2
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:26 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:23:52 -03:00

perf tools: Introduce perf_evlist__mmap_cb_idx()

Add perf_evlist__mmap_cb_idx function to call auxtrace_mmap_params__set_idx()
on each new index during perf_evlist__mmap_ops call.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-19-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index a9b189a..11716f2 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -739,6 +739,17 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, 
int idx,
return 0;
 }
 
+static void
+perf_evlist__mmap_cb_idx(struct perf_evlist *_evlist,
+struct perf_mmap_param *_mp,
+int idx, bool per_cpu)
+{
+   struct evlist *evlist = container_of(_evlist, struct evlist, core);
+   struct mmap_params *mp = container_of(_mp, struct mmap_params, core);
+
+   auxtrace_mmap_params__set_idx(>auxtrace_mp, evlist, idx, per_cpu);
+}
+
 static int evlist__mmap_per_cpu(struct evlist *evlist,
 struct mmap_params *mp)
 {
@@ -935,6 +946,9 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int 
pages,
.flush  = flush,
.comp_level = comp_level
};
+   struct perf_evlist_mmap_ops ops __maybe_unused = {
+   .idx = perf_evlist__mmap_cb_idx,
+   };
 
if (!evlist->mmap)
evlist->mmap = evlist__alloc_mmap(evlist, false);


[tip: perf/core] libperf: Adopt perf_evlist__mmap()/munmap() from tools/perf

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: d1a177595b3a824c72dacb0f9d1a4e5906eaef0e
Gitweb:
https://git.kernel.org/tip/d1a177595b3a824c72dacb0f9d1a4e5906eaef0e
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:21 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:15:58 -03:00

libperf: Adopt perf_evlist__mmap()/munmap() from tools/perf

Add libperf's version of perf_evlist__mmap()/munmap() functions and
exporting them in the perf/evlist.h header.

It's the backbone of what we have in perf code. The following changes
will add needed callbacks and then we'll finally switch the perf code to
use libperf's version.

Add mmap/mmap_ovw 'struct perf_mmap' object arrays to hold maps for
libperf's evlist.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-14-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 236 ++-
 tools/perf/lib/include/internal/evlist.h |   2 +-
 tools/perf/lib/include/perf/evlist.h |   3 +-
 tools/perf/lib/libperf.map   |   2 +-
 4 files changed, 243 insertions(+)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index d1496fe..250ad57 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -8,13 +8,20 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -103,6 +110,10 @@ perf_evlist__next(struct perf_evlist *evlist, struct 
perf_evsel *prev)
 
 void perf_evlist__delete(struct perf_evlist *evlist)
 {
+   if (evlist == NULL)
+   return;
+
+   perf_evlist__munmap(evlist);
free(evlist);
 }
 
@@ -281,3 +292,228 @@ int perf_evlist__poll(struct perf_evlist *evlist, int 
timeout)
 {
return fdarray__poll(>pollfd, timeout);
 }
+
+static struct perf_mmap* perf_evlist__alloc_mmap(struct perf_evlist *evlist, 
bool overwrite)
+{
+   int i;
+   struct perf_mmap *map;
+
+   evlist->nr_mmaps = perf_cpu_map__nr(evlist->cpus);
+   if (perf_cpu_map__empty(evlist->cpus))
+   evlist->nr_mmaps = perf_thread_map__nr(evlist->threads);
+
+   map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
+   if (!map)
+   return NULL;
+
+   for (i = 0; i < evlist->nr_mmaps; i++) {
+   /*
+* When the perf_mmap() call is made we grab one refcount, plus
+* one extra to let perf_mmap__consume() get the last
+* events after all real references (perf_mmap__get()) are
+* dropped.
+*
+* Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and
+* thus does perf_mmap__get() on it.
+*/
+   perf_mmap__init([i], overwrite, NULL);
+   }
+
+   return map;
+}
+
+static void perf_evlist__set_sid_idx(struct perf_evlist *evlist,
+struct perf_evsel *evsel, int idx, int cpu,
+int thread)
+{
+   struct perf_sample_id *sid = SID(evsel, cpu, thread);
+
+   sid->idx = idx;
+   if (evlist->cpus && cpu >= 0)
+   sid->cpu = evlist->cpus->map[cpu];
+   else
+   sid->cpu = -1;
+   if (!evsel->system_wide && evlist->threads && thread >= 0)
+   sid->tid = perf_thread_map__pid(evlist->threads, thread);
+   else
+   sid->tid = -1;
+}
+
+static struct perf_mmap*
+perf_evlist__map_get(struct perf_evlist *evlist, bool overwrite, int idx)
+{
+   struct perf_mmap *map = >mmap[idx];
+
+   if (overwrite) {
+   if (!evlist->mmap_ovw) {
+   evlist->mmap_ovw = perf_evlist__alloc_mmap(evlist, 
true);
+   if (!evlist->mmap_ovw)
+   return NULL;
+   }
+   map = >mmap_ovw[idx];
+   }
+
+   return map;
+}
+
+#define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
+
+static int
+mmap_per_evsel(struct perf_evlist *evlist, int idx,
+  struct perf_mmap_param *mp, int cpu_idx,
+  int thread, int *_output, int *_output_overwrite)
+{
+   int evlist_cpu = perf_cpu_map__cpu(evlist->cpus, cpu_idx);
+   struct perf_evsel *evsel;
+   int revent;
+
+   perf_evlist__for_each_entry(evlist, evsel) {
+   bool overwrite = evsel->attr.write_backward;
+   struct perf_mmap *map;
+   int *output, fd, cpu;
+
+   if (evsel->system_wide && thread)
+   continue;
+
+   cpu = perf_cpu_map__idx(evsel->cpus, evlist_cpu);
+   if (cpu == -1)
+   continue;
+

[tip: perf/core] libperf: Introduce perf_evlist__purge()

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 696f27c994ed056fd176ce9dc51c7988e148e4b0
Gitweb:
https://git.kernel.org/tip/696f27c994ed056fd176ce9dc51c7988e148e4b0
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:33 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:57:22 -03:00

libperf: Introduce perf_evlist__purge()

Add a static perf_evlist__purge() function to purge evsels from a evlist.

Add also perf_evlist__for_each_entry_safe() which is used by
perf_evlist__purge().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-26-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 13 +
 tools/perf/lib/include/internal/evlist.h | 18 ++
 2 files changed, 31 insertions(+)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 7ba98f0..9534ad9 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -109,6 +109,18 @@ perf_evlist__next(struct perf_evlist *evlist, struct 
perf_evsel *prev)
return next;
 }
 
+static void perf_evlist__purge(struct perf_evlist *evlist)
+{
+   struct perf_evsel *pos, *n;
+
+   perf_evlist__for_each_entry_safe(evlist, n, pos) {
+   list_del_init(>node);
+   perf_evsel__delete(pos);
+   }
+
+   evlist->nr_entries = 0;
+}
+
 void perf_evlist__exit(struct perf_evlist *evlist)
 {
perf_cpu_map__put(evlist->cpus);
@@ -125,6 +137,7 @@ void perf_evlist__delete(struct perf_evlist *evlist)
 
perf_evlist__munmap(evlist);
perf_evlist__close(evlist);
+   perf_evlist__purge(evlist);
perf_evlist__exit(evlist);
free(evlist);
 }
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index 0721512..be0b25a 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -82,6 +82,24 @@ void perf_evlist__exit(struct perf_evlist *evlist);
 #define perf_evlist__for_each_entry_reverse(evlist, evsel) \
__perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
 
+/**
+ * __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
+ * @list: list_head instance to iterate
+ * @tmp: struct evsel temp iterator
+ * @evsel: struct evsel iterator
+ */
+#define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \
+   list_for_each_entry_safe(evsel, tmp, list, node)
+
+/**
+ * perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
+ * @evlist: evlist instance to iterate
+ * @evsel: struct evsel iterator
+ * @tmp: struct evsel temp iterator
+ */
+#define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \
+   __perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel)
+
 static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
 {
return list_entry(evlist->entries.next, struct perf_evsel, node);


[tip: perf/core] libperf: Introduce perf_evlist_mmap_ops::mmap callback

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: b5911e7ac28cb34f21b7380915ce98518078f114
Gitweb:
https://git.kernel.org/tip/b5911e7ac28cb34f21b7380915ce98518078f114
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:25 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:22:21 -03:00

libperf: Introduce perf_evlist_mmap_ops::mmap callback

Add the perf_evlist_mmap_ops::mmap callback to be called in
mmap_per_evsel() to actually mmap the map.

Add libperf's perf_evlist__mmap_cb_mmap() function as libperf's mmap
callback.

New mmaped map gets refcount set to 2 in mmap__mmap(), we follow that in
mmap callback. We will move this to common place after we switch to
perf_evlist__mmap().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-18-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 29 ---
 tools/perf/lib/include/internal/evlist.h |  3 ++-
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 4f49de5..b697226 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -359,6 +359,28 @@ perf_evlist__mmap_cb_get(struct perf_evlist *evlist, bool 
overwrite, int idx)
 #define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
 
 static int
+perf_evlist__mmap_cb_mmap(struct perf_mmap *map, struct perf_mmap_param *mp,
+ int output, int cpu)
+{
+   /*
+* The last one will be done at perf_mmap__consume(), so that we
+* make sure we don't prevent tools from consuming every last event in
+* the ring buffer.
+*
+* I.e. we can get the POLLHUP meaning that the fd doesn't exist
+* anymore, but the last events for it are still in the ring buffer,
+* waiting to be consumed.
+*
+* Tools can chose to ignore this at their own discretion, but the
+* evlist layer can't just drop it when filtering events in
+* perf_evlist__filter_pollfd().
+*/
+   refcount_set(>refcnt, 2);
+
+   return perf_mmap__mmap(map, mp, output, cpu);
+}
+
+static int
 mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
   int idx, struct perf_mmap_param *mp, int cpu_idx,
   int thread, int *_output, int *_output_overwrite)
@@ -396,7 +418,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct 
perf_evlist_mmap_ops *ops,
if (*output == -1) {
*output = fd;
 
-   if (perf_mmap__mmap(map, mp, *output, evlist_cpu) < 0)
+   if (ops->mmap(map, mp, *output, evlist_cpu) < 0)
return -1;
} else {
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
@@ -488,7 +510,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
const struct perf_cpu_map *cpus = evlist->cpus;
const struct perf_thread_map *threads = evlist->threads;
 
-   if (!ops || !ops->get)
+   if (!ops || !ops->get || !ops->mmap)
return -EINVAL;
 
if (!evlist->mmap)
@@ -513,7 +535,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
 {
struct perf_mmap_param mp;
struct perf_evlist_mmap_ops ops = {
-   .get = perf_evlist__mmap_cb_get,
+   .get  = perf_evlist__mmap_cb_get,
+   .mmap = perf_evlist__mmap_cb_mmap,
};
 
evlist->mmap_len = (pages + 1) * page_size;
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index 9bc3a21..b201970 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -31,10 +31,13 @@ typedef void
 (*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, 
int, bool);
 typedef struct perf_mmap*
 (*perf_evlist_mmap__cb_get_t)(struct perf_evlist*, bool, int);
+typedef int
+(*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, 
int, int);
 
 struct perf_evlist_mmap_ops {
perf_evlist_mmap__cb_idx_t  idx;
perf_evlist_mmap__cb_get_t  get;
+   perf_evlist_mmap__cb_mmap_t mmap;
 };
 
 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);


[tip: perf/core] libperf: Add perf_evlist_mmap_ops::get callback

2019-10-14 Thread tip-bot2 for Jiri Olsa
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 3a8bb58121987a8405d6f96cd8815025e564605d
Gitweb:
https://git.kernel.org/tip/3a8bb58121987a8405d6f96cd8815025e564605d
Author:Jiri Olsa 
AuthorDate:Mon, 07 Oct 2019 14:53:24 +02:00
Committer: Arnaldo Carvalho de Melo 
CommitterDate: Thu, 10 Oct 2019 12:21:11 -03:00

libperf: Add perf_evlist_mmap_ops::get callback

Add the perf_evlist_mmap_ops::get callback to be called in
mmap_per_evsel() to get/allocate the 'struct perf_mmap' object.

Add the libperf's perf_evlist__mmap_cb_get() function as libperf's get
callback.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lore.kernel.org/lkml/20191007125344.14268-17-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 18 ++
 tools/perf/lib/include/internal/evlist.h |  3 +++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 3832d3e..4f49de5 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -340,7 +340,7 @@ static void perf_evlist__set_sid_idx(struct perf_evlist 
*evlist,
 }
 
 static struct perf_mmap*
-perf_evlist__map_get(struct perf_evlist *evlist, bool overwrite, int idx)
+perf_evlist__mmap_cb_get(struct perf_evlist *evlist, bool overwrite, int idx)
 {
struct perf_mmap *map = >mmap[idx];
 
@@ -359,8 +359,8 @@ perf_evlist__map_get(struct perf_evlist *evlist, bool 
overwrite, int idx)
 #define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
 
 static int
-mmap_per_evsel(struct perf_evlist *evlist, int idx,
-  struct perf_mmap_param *mp, int cpu_idx,
+mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops,
+  int idx, struct perf_mmap_param *mp, int cpu_idx,
   int thread, int *_output, int *_output_overwrite)
 {
int evlist_cpu = perf_cpu_map__cpu(evlist->cpus, cpu_idx);
@@ -379,7 +379,7 @@ mmap_per_evsel(struct perf_evlist *evlist, int idx,
if (cpu == -1)
continue;
 
-   map = perf_evlist__map_get(evlist, overwrite, idx);
+   map = ops->get(evlist, overwrite, idx);
if (map == NULL)
return -ENOMEM;
 
@@ -439,7 +439,7 @@ mmap_per_thread(struct perf_evlist *evlist, struct 
perf_evlist_mmap_ops *ops,
if (ops->idx)
ops->idx(evlist, mp, thread, false);
 
-   if (mmap_per_evsel(evlist, thread, mp, 0, thread,
+   if (mmap_per_evsel(evlist, ops, thread, mp, 0, thread,
   , _overwrite))
goto out_unmap;
}
@@ -467,7 +467,7 @@ mmap_per_cpu(struct perf_evlist *evlist, struct 
perf_evlist_mmap_ops *ops,
ops->idx(evlist, mp, cpu, true);
 
for (thread = 0; thread < nr_threads; thread++) {
-   if (mmap_per_evsel(evlist, cpu, mp, cpu,
+   if (mmap_per_evsel(evlist, ops, cpu, mp, cpu,
   thread, , _overwrite))
goto out_unmap;
}
@@ -488,7 +488,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
const struct perf_cpu_map *cpus = evlist->cpus;
const struct perf_thread_map *threads = evlist->threads;
 
-   if (!ops)
+   if (!ops || !ops->get)
return -EINVAL;
 
if (!evlist->mmap)
@@ -512,7 +512,9 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist,
 int perf_evlist__mmap(struct perf_evlist *evlist, int pages)
 {
struct perf_mmap_param mp;
-   struct perf_evlist_mmap_ops ops = { 0 };
+   struct perf_evlist_mmap_ops ops = {
+   .get = perf_evlist__mmap_cb_get,
+   };
 
evlist->mmap_len = (pages + 1) * page_size;
mp.mask = evlist->mmap_len - page_size - 1;
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index 053f620..9bc3a21 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -29,9 +29,12 @@ struct perf_evlist {
 
 typedef void
 (*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, 
int, bool);
+typedef struct perf_mmap*
+(*perf_evlist_mmap__cb_get_t)(struct perf_evlist*, bool, int);
 
 struct perf_evlist_mmap_ops {
perf_evlist_mmap__cb_idx_t  idx;
+   perf_evlist_mmap__cb_get_t  get;
 };
 
 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);


Re: [GIT PULL] perf/core improvements and fixes

2019-10-14 Thread Ingo Molnar


* Arnaldo Carvalho de Melo  wrote:

> Hi Ingo,
> 
>   Please consider pulling,
> 
> Best regards,
> 
> - Arnaldo
> 
> Test results at the end of this message, as usual.
> 
> The following changes since commit f733c6b508bcaa3441ba1eacf16efb9abd47489f:
> 
>   perf/core: Fix inheritance of aux_output groups (2019-10-07 16:50:42 +0200)
> 
> are available in the Git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
> tags/perf-core-for-mingo-5.5-20191011
> 
> for you to fetch changes up to cebf7d51a6c3babc4d0589da7aec0de1af0a5691:
> 
>   perf diff: Report noisy for cycles diff (2019-10-11 10:57:00 -0300)

Pulled, thanks a lot Arnaldo!

Ingo


linux-next: Tree for Oct 15

2019-10-14 Thread Stephen Rothwell
Hi all,

Changes since 20191014:

Renamed tree: thermal to thermal-zhang
New tree: thermal

The pm tree gained a build failure so I used the version from
next-20191014.

The drivers-x86 tree gained a build failure do I used the version from
next-20191014.

Non-merge commits (relative to Linus' tree): 3826
 3892 files changed, 131624 insertions(+), 62239 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc, an allmodconfig for x86_64, a
multi_v7_defconfig for arm and a native build of tools/perf. After
the final fixups (if any), I do an x86_64 modules_install followed by
builds for x86_64 allnoconfig, powerpc allnoconfig (32 and 64 bit),
ppc44x_defconfig, allyesconfig and pseries_le_defconfig and i386, sparc
and sparc64 defconfig. And finally, a simple boot test of the powerpc
pseries_le_defconfig kernel in qemu (with and without kvm enabled).

Below is a summary of the state of the merge.

I am currently merging 314 trees (counting Linus' and 78 trees of bug
fix patches pending for the current merge release).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (2abd839aa7e6 kmemleak: Do not corrupt the object_list 
during clean-up)
Merging fixes/master (54ecb8f7028c Linux 5.4-rc1)
Merging kbuild-current/fixes (b8d5e105ebbf scripts: setlocalversion: fix a 
bashism)
Merging arc-current/for-curr (41277ba7eb4e ARC: mm: tlb flush optim: elide 
redundant uTLB invalidates for MMUv3)
Merging arm-current/fixes (4c0742f65b4e ARM: 8914/1: NOMMU: Fix exc_ret for XIP)
Merging arm-soc-fixes/arm/fixes (dd163ca3fb49 Merge tag 'mvebu-fixes-5.4-1' of 
git://git.infradead.org/linux-mvebu into arm/fixes)
Merging arm64-fixes/for-next/fixes (86109a691a45 arm64: Fix kcore macros after 
52-bit virtual addressing fallout)
Merging m68k-current/for-linus (0f1979b402df m68k: Remove ioremap_fullcache())
Merging powerpc-fixes/fixes (2272905a4580 spufs: fix a crash in 
spufs_create_root())
Merging s390-fixes/fixes (062795fcdcb2 s390/uaccess: avoid (false positive) 
compiler warnings)
Merging sparc/master (038029c03e21 sparc: remove unneeded uapi/asm/statfs.h)
Merging fscrypt-current/for-stable (ae64f9bd1d36 Linux 4.15-rc2)
Merging net/master (33902b4a4227 netdevsim: Fix error handling in nsim_fib_init 
and nsim_fib_exit)
Merging bpf/master (9e8acd9c44a0 bpf: lwtunnel: Fix reroute supplying invalid 
dst)
Merging ipsec/master (68ce6688a5ba net: sched: taprio: Fix potential integer 
overflow in taprio_set_picos_per_byte)
Merging netfilter/master (503c9addef61 ptp: fix typo of "mechanism" in Kconfig 
help text)
Merging ipvs/master (503c9addef61 ptp: fix typo of "mechanism" in Kconfig help 
text)
Merging wireless-drivers/master (d79749f7716d ath10k: fix latency issue for 
QCA988x)
Merging mac80211/master (82ad862115c2 Merge branch 'smc-fixes')
Merging rdma-fixes/for-rc (0417791536ae RDMA/mlx5: Add missing 
synchronize_srcu() for MW cases)
Merging sound-current/for-linus (130bce3afbbb ALSA: hdac: clear link output 
stream mapping)
Merging sound-asoc-fixes/for-linus (47e68c204195 Merge branch 'asoc-5.4' into 
asoc-linus)
Merging regmap-fixes/for-linus (da0c9ea146cb Linux 5.4-rc2)
Merging regulator-fixes/for-linus (68a2d13c4d54 Merge branch 'regulator-5.4' 
into regulator-linus)
Merging spi-fixes/for-linus (614f984bf23b Merge branch 'spi-5.4' into spi-linus)
Merging pci-current/for-linus (54ecb8f7028c Linux 5.4-rc1)
Merging driver-core.current/driver-core-linus (82af5b660967 sysfs: Fixes 
__BIN_ATTR_WO() macro)
Merging tty.current/tty-linus (4f5cafb5cb84 Linux 5.4-rc3)
Merging usb.current/usb-linus (4f5cafb5cb84 Linux 5.4-rc3)
Merging usb-gadget-fixes/fixes (4a56a478a525 usb: gadget: mass_storage: Fix 
races between fsg_disable and fsg_set_alt)
Merging usb-serial-fixes/usb-linus (4f5cafb5cb84 Linux 5.4-rc3)
Merging usb-chipidea-fixes/ci-for-usb-stable (16009db47c51 usb: chipidea: udc:

Re: [PATCH] PCI: PM: Fix pci_power_up()

2019-10-14 Thread Daniel Drake
On Mon, Oct 14, 2019 at 7:25 PM Rafael J. Wysocki  wrote:
> Since there is no reason for that difference to exist, modify
> pci_power_up() to follow pci_set_power_state() more closely and
> invoke __pci_start_power_transition() from there to call the
> platform firmware to power up the device (in case that's necessary).
>
> Fixes: db288c9c5f9d ("PCI / PM: restore the original behavior of 
> pci_set_power_state()")
> Reported-by: Daniel Drake 
> Link: 
> https://lore.kernel.org/linux-pm/cad8lp44tyxrmgplkhcqf9hv6smeurmxvmmvmtyfhz6q4se+...@mail.gmail.com/T/#m21be74af263c6a34f36e0fc5c77c5449d9406925
> Signed-off-by: Rafael J. Wysocki 
> ---
>
> Daniel, please test this one.

This one is working too, thanks

Daniel


KMSAN: uninit-value in ax88172a_bind

2019-10-14 Thread syzbot

Hello,

syzbot found the following crash on:

HEAD commit:fa169025 kmsan: get rid of unused static functions in kmsa..
git tree:   https://github.com/google/kmsan.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=1432a65360
kernel config:  https://syzkaller.appspot.com/x/.config?x=49548798e87d32d7
dashboard link: https://syzkaller.appspot.com/bug?extid=a8d4acdad35e6bbca308
compiler:   clang version 9.0.0 (/home/glider/llvm/clang  
80fee25776c2fb61e74c1ecb1a523375c2500b69)

syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=14743a6f60
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=125bdbc760

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+a8d4acdad35e6bbca...@syzkaller.appspotmail.com

usb 1-1: config 0 has no interface number 0
usb 1-1: New USB device found, idVendor=0b95, idProduct=172a,  
bcdDevice=9b.e9

usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
usb 1-1: config 0 descriptor??
=
BUG: KMSAN: uninit-value in ax88172a_bind+0x76d/0xf80  
drivers/net/usb/ax88172a.c:217

CPU: 1 PID: 3632 Comm: kworker/1:2 Not tainted 5.4.0-rc2+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011

Workqueue: usb_hub_wq hub_event
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x191/0x1f0 lib/dump_stack.c:113
 kmsan_report+0x14e/0x2c0 mm/kmsan/kmsan_report.c:110
 __msan_warning+0x73/0xe0 mm/kmsan/kmsan_instr.c:245
 ax88172a_bind+0x76d/0xf80 drivers/net/usb/ax88172a.c:217
 usbnet_probe+0x10d3/0x39d0 drivers/net/usb/usbnet.c:1730
 usb_probe_interface+0xd19/0x1310 drivers/usb/core/driver.c:361
 really_probe+0xd91/0x1f90 drivers/base/dd.c:552
 driver_probe_device+0x1ba/0x510 drivers/base/dd.c:721
 __device_attach_driver+0x5b8/0x790 drivers/base/dd.c:828
 bus_for_each_drv+0x28e/0x3b0 drivers/base/bus.c:430
 __device_attach+0x489/0x750 drivers/base/dd.c:894
 device_initial_probe+0x4a/0x60 drivers/base/dd.c:941
 bus_probe_device+0x131/0x390 drivers/base/bus.c:490
 device_add+0x25b5/0x2df0 drivers/base/core.c:2201
 usb_set_configuration+0x309f/0x3710 drivers/usb/core/message.c:2027
 generic_probe+0xe7/0x280 drivers/usb/core/generic.c:210
 usb_probe_device+0x146/0x200 drivers/usb/core/driver.c:266
 really_probe+0xd91/0x1f90 drivers/base/dd.c:552
 driver_probe_device+0x1ba/0x510 drivers/base/dd.c:721
 __device_attach_driver+0x5b8/0x790 drivers/base/dd.c:828
 bus_for_each_drv+0x28e/0x3b0 drivers/base/bus.c:430
 __device_attach+0x489/0x750 drivers/base/dd.c:894
 device_initial_probe+0x4a/0x60 drivers/base/dd.c:941
 bus_probe_device+0x131/0x390 drivers/base/bus.c:490
 device_add+0x25b5/0x2df0 drivers/base/core.c:2201
 usb_new_device+0x23e5/0x2fb0 drivers/usb/core/hub.c:2536
 hub_port_connect drivers/usb/core/hub.c:5098 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5213 [inline]
 port_event drivers/usb/core/hub.c:5359 [inline]
 hub_event+0x581d/0x72f0 drivers/usb/core/hub.c:5441
 process_one_work+0x1572/0x1ef0 kernel/workqueue.c:2269
 worker_thread+0x111b/0x2460 kernel/workqueue.c:2415
 kthread+0x4b5/0x4f0 kernel/kthread.c:256
 ret_from_fork+0x35/0x40 arch/x86/entry/entry_64.S:355

Local variable description: buf@ax88172a_bind
Variable was created at:
 ax88172a_bind+0x66/0xf80 drivers/net/usb/ax88172a.c:186
 ax88172a_bind+0x66/0xf80 drivers/net/usb/ax88172a.c:186
=


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkal...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches


Re: [RFC v2 0/2] kvm: Use host timekeeping in guest.

2019-10-14 Thread Suleiman Souhlal
On Thu, Oct 10, 2019 at 7:39 PM Roman Kagan  wrote:
>
> I wonder how feasible it is to map the host's vdso into the guest and
> thus make the guest use the *same* (as opposed to "synchronized") clock
> as the host's userspace?  Another benefit is that it's essentially an
> ABI so is not changed as liberally as internal structures like
> timekeeper, etc.  There is probably certain complication in handling the
> syscall fallback in the vdso when used in the guest kernel, though.
>
> You'll also need to ensure neither tsc scaling and nor offsetting is
> applied to the VM once this clock is enabled.

That is what I initially wanted to do, but I couldn't find an easy way
to map a host page into the guest, outside of the regular userspace
(ioctl) KVM way of adding memory to a VM.

-- Suleiman


[PATCH v2 2/2] kasan: add test for invalid size in memmove

2019-10-14 Thread Walter Wu
Test negative size in memmove in order to verify whether it correctly
get KASAN report.

Casting negative numbers to size_t would indeed turn up as a 'large'
size_t, so it will have out-of-bounds bug and detected by KASAN.

Changes in v2:
Add some descriptions for clarity the testcase.

Signed-off-by: Walter Wu 
Reviewed-by: Dmitry Vyukov 
---
 lib/test_kasan.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 49cc4d570a40..06942cf585cc 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -283,6 +283,23 @@ static noinline void __init kmalloc_oob_in_memset(void)
kfree(ptr);
 }
 
+static noinline void __init kmalloc_memmove_invalid_size(void)
+{
+   char *ptr;
+   size_t size = 64;
+
+   pr_info("invalid size in memmove\n");
+   ptr = kmalloc(size, GFP_KERNEL);
+   if (!ptr) {
+   pr_err("Allocation failed\n");
+   return;
+   }
+
+   memset((char *)ptr, 0, 64);
+   memmove((char *)ptr, (char *)ptr + 4, -2);
+   kfree(ptr);
+}
+
 static noinline void __init kmalloc_uaf(void)
 {
char *ptr;
@@ -773,6 +790,7 @@ static int __init kmalloc_tests_init(void)
kmalloc_oob_memset_4();
kmalloc_oob_memset_8();
kmalloc_oob_memset_16();
+   kmalloc_memmove_invalid_size();
kmalloc_uaf();
kmalloc_uaf_memset();
kmalloc_uaf2();
-- 
2.18.0



[v2,1/2] dt-bindings: i2c: add property idle-state

2019-10-14 Thread Biwen Li
This adds property idle-state

Signed-off-by: Biwen Li 
---
Change in v2:
- update subject and description
- add property idle-state

 Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt 
b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt
index 30ac6a60f041..2c7875d338fb 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt
@@ -34,6 +34,7 @@ Optional Properties:
 - first cell is the pin number
 - second cell is used to specify flags.
 See also 
Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+  - idle-state: Please refer to 
Documentation/devicetree/bindings/mux/mux-controller.txt
 
 Example:
 
-- 
2.17.1



[v2,2/2] i2c: mux: pca954x: add property idle-state

2019-10-14 Thread Biwen Li
This adds property idle-state

Signed-off-by: Biwen Li 
---
Change in v2:
- update subject and description
- add property idle-state

 drivers/i2c/muxes/i2c-mux-pca954x.c | 47 ++---
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c 
b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 923aa3a5a3dc..8ec586342b92 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -86,7 +86,7 @@ struct pca954x {
 
u8 last_chan;   /* last register value */
/* MUX_IDLE_AS_IS, MUX_IDLE_DISCONNECT or >= 0 for channel */
-   s8 idle_state;
+   s32 idle_state;
 
struct i2c_client *client;
 
@@ -256,7 +256,7 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, 
u32 chan)
 {
struct pca954x *data = i2c_mux_priv(muxc);
struct i2c_client *client = data->client;
-   s8 idle_state;
+   s32 idle_state;
 
idle_state = READ_ONCE(data->idle_state);
if (idle_state >= 0)
@@ -402,6 +402,25 @@ static void pca954x_cleanup(struct i2c_mux_core *muxc)
i2c_mux_del_adapters(muxc);
 }
 
+static int pca954x_init(struct i2c_client *client, struct pca954x *data)
+{
+   /*
+* Write the mux register at addr to verify
+* that the mux is in fact present. This also
+* initializes the mux to disconnected state.
+*/
+   if (data->idle_state >= 0) {
+   /* Always enable multiplexer */
+   if (data->chip->muxtype == pca954x_ismux)
+   data->last_chan = data->idle_state | data->chip->enable;
+   else
+   data->last_chan = 1 << data->idle_state;
+   } else {
+   /* Disconnect multiplexer */
+   data->last_chan = 0; /* force the first selection */
+   }
+   return i2c_smbus_write_byte(client, data->last_chan);
+}
 /*
  * I2C init/probing/exit functions
  */
@@ -411,7 +430,6 @@ static int pca954x_probe(struct i2c_client *client,
struct i2c_adapter *adap = client->adapter;
struct device *dev = >dev;
struct device_node *np = dev->of_node;
-   bool idle_disconnect_dt;
struct gpio_desc *gpio;
struct i2c_mux_core *muxc;
struct pca954x *data;
@@ -462,22 +480,18 @@ static int pca954x_probe(struct i2c_client *client,
}
}
 
-   /* Write the mux register at addr to verify
-* that the mux is in fact present. This also
-* initializes the mux to disconnected state.
-*/
-   if (i2c_smbus_write_byte(client, 0) < 0) {
+   if (of_property_read_u32(np, "idle-state", >idle_state))
+   data->idle_state = MUX_IDLE_AS_IS;
+
+   if (of_property_read_bool(np, "i2c-mux-idle-disconnect"))
+   data->idle_state = MUX_IDLE_DISCONNECT;
+
+   ret = pca954x_init(client, data);
+   if (ret < 0) {
dev_warn(dev, "probe failed\n");
return -ENODEV;
}
 
-   data->last_chan = 0;   /* force the first selection */
-   data->idle_state = MUX_IDLE_AS_IS;
-
-   idle_disconnect_dt = np &&
-   of_property_read_bool(np, "i2c-mux-idle-disconnect");
-   if (idle_disconnect_dt)
-   data->idle_state = MUX_IDLE_DISCONNECT;
 
ret = pca954x_irq_setup(muxc);
if (ret)
@@ -531,8 +545,7 @@ static int pca954x_resume(struct device *dev)
struct i2c_mux_core *muxc = i2c_get_clientdata(client);
struct pca954x *data = i2c_mux_priv(muxc);
 
-   data->last_chan = 0;
-   return i2c_smbus_write_byte(client, 0);
+   return pca954x_init(client, data);
 }
 #endif
 
-- 
2.17.1



Re: [PATCH] cifs: Fix missed free operations

2019-10-14 Thread Steve French
Merged into cifs-2.6.git for-next and cc: stable for 5.3

On Mon, Oct 14, 2019 at 4:43 PM Pavel Shilovsky via samba-technical
 wrote:
>
> пн, 14 окт. 2019 г. в 00:18, Chuhong Yuan :
> >
> > cifs_setattr_nounix has two paths which miss free operations
> > for xid and fullpath.
> > Use goto cifs_setattr_exit like other paths to fix them.
> >
> > Fixes: aa081859b10c ("cifs: flush before set-info if we have writeable 
> > handles")
> > Signed-off-by: Chuhong Yuan 
> > ---
> >  fs/cifs/inode.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
> > index 5dcc95b38310..df9377828e2f 100644
> > --- a/fs/cifs/inode.c
> > +++ b/fs/cifs/inode.c
> > @@ -2475,9 +2475,9 @@ cifs_setattr_nounix(struct dentry *direntry, struct 
> > iattr *attrs)
> > rc = tcon->ses->server->ops->flush(xid, tcon, 
> > >fid);
> > cifsFileInfo_put(wfile);
> > if (rc)
> > -   return rc;
> > +   goto cifs_setattr_exit;
> > } else if (rc != -EBADF)
> > -   return rc;
> > +   goto cifs_setattr_exit;
> > else
> > rc = 0;
> > }
> > --
> > 2.20.1
> >
>
> Looks good, thanks.
>
> Reviewed-by: Pavel Shilovsky 
>
> The original patch was tagged for stable, so, it seems that this one
> should be tagged too.
>
> --
> Best regards,
> Pavel Shilovsky
>


-- 
Thanks,

Steve


[PATCH V2] hugetlb: Add nohugepages parameter to prevent hugepages creation

2019-10-14 Thread Guilherme G. Piccoli
Currently there are 2 ways for setting HugeTLB hugepages in kernel; either
users pass parameters on kernel command-line or they can write to sysfs
files (which is effectively the sysctl way).

Kdump kernels won't benefit from hugepages - in fact it's quite opposite,
it may be the case hugepages on kdump kernel can lead to OOM if kernel
gets unable to allocate demanded pages due to the fact the preallocated
hugepages are consuming a lot of memory.

This patch proposes a new kernel parameter to prevent the creation of
HugeTLB hugepages - we currently don't have a way to do that. We can
even have kdump scripts removing the kernel command-line options to
set hugepages, but it's not straightforward to prevent sysctl/sysfs
configuration, given it happens in later boot or anytime when the
system is running.

Signed-off-by: Guilherme G. Piccoli 
---
 .../admin-guide/kernel-parameters.txt |  4 +++
 fs/hugetlbfs/inode.c  |  5 ++--
 include/linux/hugetlb.h   |  7 ++
 mm/hugetlb.c  | 25 +--
 4 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index a84a83f8881e..061bec851114 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2982,6 +2982,10 @@
 
nohugeiomap [KNL,x86,PPC] Disable kernel huge I/O mappings.
 
+   nohugepages [KNL] Disable HugeTLB hugepages completely, preventing
+   its setting either by kernel parameter or sysfs;
+   useful specially in kdump kernel.
+
nosmt   [KNL,S390] Disable symmetric multithreading (SMT).
Equivalent to smt=1.
 
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index a478df035651..bbf8827ecccf 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1451,8 +1451,9 @@ static int __init init_hugetlbfs_fs(void)
int error;
int i;
 
-   if (!hugepages_supported()) {
-   pr_info("disabling because there are no supported hugepage 
sizes\n");
+   if (!hugepages_enabled()) {
+   if (!hugetlb_disable_hugepages)
+   pr_info("disabling because there are no supported 
hugepage sizes\n");
return -ENOTSUPP;
}
 
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 53fc34f930d0..91b3cc7ae891 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -549,6 +549,13 @@ static inline spinlock_t *huge_pte_lockptr(struct hstate 
*h,
 #define hugepages_supported() (HPAGE_SHIFT != 0)
 #endif
 
+extern int hugetlb_disable_hugepages;
+
+static inline bool hugepages_enabled(void)
+{
+   return (hugepages_supported() && (!hugetlb_disable_hugepages));
+}
+
 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm);
 
 static inline void hugetlb_count_add(long l, struct mm_struct *mm)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ef37c85423a5..d0151454f13f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -43,6 +43,8 @@
 int hugetlb_max_hstate __read_mostly;
 unsigned int default_hstate_idx;
 struct hstate hstates[HUGE_MAX_HSTATE];
+int hugetlb_disable_hugepages;
+
 /*
  * Minimum page order among possible hugepage sizes, set to a proper value
  * at boot time.
@@ -1604,7 +1606,7 @@ int dissolve_free_huge_pages(unsigned long start_pfn, 
unsigned long end_pfn)
struct page *page;
int rc = 0;
 
-   if (!hugepages_supported())
+   if (!hugepages_enabled())
return rc;
 
for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) {
@@ -2897,7 +2899,7 @@ static int __init hugetlb_init(void)
 {
int i;
 
-   if (!hugepages_supported())
+   if (!hugepages_enabled())
return 0;
 
if (!size_to_hstate(default_hstate_size)) {
@@ -3022,6 +3024,15 @@ static int __init hugetlb_default_setup(char *s)
 }
 __setup("default_hugepagesz=", hugetlb_default_setup);
 
+static int __init nohugepages_setup(char *str)
+{
+   hugetlb_disable_hugepages = 1;
+   pr_info("HugeTLB: hugepages disabled by kernel parameter\n");
+
+   return 0;
+}
+early_param("nohugepages", nohugepages_setup);
+
 static unsigned int cpuset_mems_nr(unsigned int *array)
 {
int node;
@@ -3042,7 +3053,7 @@ static int hugetlb_sysctl_handler_common(bool 
obey_mempolicy,
unsigned long tmp = h->max_huge_pages;
int ret;
 
-   if (!hugepages_supported())
+   if (!hugepages_enabled())
return -EOPNOTSUPP;
 
table->data = 
@@ -3083,7 +3094,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, 
int write,
unsigned long tmp;
int ret;
 
-   if (!hugepages_supported())
+   if (!hugepages_enabled())
return -EOPNOTSUPP;
 
tmp = 

[PATCH v2] MIPS: Loongson: Make default kernel log buffer size as 256KB for Loongson3

2019-10-14 Thread Tiezhu Yang
When I update kernel with loongson3_defconfig based on the Loongson 3A3000
platform, then using dmesg command to show kernel ring buffer, the initial
kernel messages have disappeared due to the log buffer is too small, it is
better to change the default kernel log buffer size from 16KB to 256KB.

Signed-off-by: Tiezhu Yang 
---

v2: modify the default kernel log buffer size to 256KB suggested by Huacai

 arch/mips/configs/loongson3_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/configs/loongson3_defconfig 
b/arch/mips/configs/loongson3_defconfig
index 90ee008..4f750e6 100644
--- a/arch/mips/configs/loongson3_defconfig
+++ b/arch/mips/configs/loongson3_defconfig
@@ -12,7 +12,7 @@ CONFIG_TASKSTATS=y
 CONFIG_TASK_DELAY_ACCT=y
 CONFIG_TASK_XACCT=y
 CONFIG_TASK_IO_ACCOUNTING=y
-CONFIG_LOG_BUF_SHIFT=14
+CONFIG_LOG_BUF_SHIFT=18
 CONFIG_MEMCG=y
 CONFIG_MEMCG_SWAP=y
 CONFIG_BLK_CGROUP=y
-- 
2.1.0




Re: [PATCH] hugetlb: Add nohugepages parameter to prevent hugepages creation

2019-10-14 Thread Guilherme G. Piccoli
On 14/10/2019 15:25, Mike Kravetz wrote:
>  [...]
> I don't know much about early_param(), so I will assume this works as you
> describe.  However, a quick grep shows hugepage options for ia64 also with
> early_param.
> 

Thanks a lot for the prompt and quite informative reply Mike.
I've checked this IA64 parameter after your mention, and it just sets
the hugepages size, I don't think it'll affect the purpose of this patch.


>> * The return when sysctl handler is prevented to progress due to
>> nohugepages is -EINVAL, but could be changed; I've just followed
>> present code there, but I'm OK changing that if we have suggestions.
> 
> It looks like you only have short circuited/prevented nr_hugepages via
> sysfs/sysctl.  Theoretically, one could set nr_overcommit_hugepages and
> still allocate hugetlb pages.  So, if you REALLY want to shut things down
> you need to stop this as well.
> 
> There is already a macro hugepages_supported() that can be set by arch
> specific code.  I wonder how difficult it would be to 'overwrite' the
> macro if nohugepages is specified.  Perhaps just a level of naming
> indirection.  This would use the existing code to prevent all hugetlb usage.
>

Outstanding! It's a much better idea to use hugepages_supported()
infrastructure, it prevents even the creation of hugepages-related sysfs
entries; I've worked a V2 with this modification, and it worked fine,
thanks for the suggestion.


> It seems like there may be some discussion about 'the right' way to
> do kdump.  I can't add to that discussion, but if such an option as
> nohugepages is needed, I can help.
> 

I think this parameter may be important/useful not only for kdump - it
is a legitimate way of disabling hugepages, something we don't currently
have on kernel. I'll submit a V2, for Ubuntu kdump specially this is
quite helpful!

Cheers,


Guilherme


Re: [PATCH v2 2/2] scsi: ufs: Add driver for TI wrapper for Cadence UFS IP

2019-10-14 Thread Vignesh Raghavendra
Hi Alim,

On 15/10/19 7:04 AM, Alim Akhtar wrote:
> Hi Vignesh
> 
> On Thu, Oct 10, 2019 at 2:05 PM Vignesh Raghavendra  wrote:
>>
>> TI's J721e SoC has a Cadence UFS IP with a TI specific wrapper. This is
>> a minimal driver to configure the wrapper. It releases the UFS slave
>> device out of reset and sets up registers to indicate PHY reference
>> clock input frequency before probing child Cadence UFS driver.
>>
>> Signed-off-by: Vignesh Raghavendra 
>> ---
>>
>> v2: No change
>>
>>  drivers/scsi/ufs/Kconfig| 10 
>>  drivers/scsi/ufs/Makefile   |  1 +
>>  drivers/scsi/ufs/ti-j721e-ufs.c | 90 +
>>  3 files changed, 101 insertions(+)
>>  create mode 100644 drivers/scsi/ufs/ti-j721e-ufs.c
>>
>> diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig
>> index 0b845ab7c3bf..d14c2243e02a 100644
>> --- a/drivers/scsi/ufs/Kconfig
>> +++ b/drivers/scsi/ufs/Kconfig
>> @@ -132,6 +132,16 @@ config SCSI_UFS_HISI
>>   Select this if you have UFS controller on Hisilicon chipset.
>>   If unsure, say N.
>>
>> +config SCSI_UFS_TI_J721E
>> +   tristate "TI glue layer for Cadence UFS Controller"
>> +   depends on OF && HAS_IOMEM && (ARCH_K3 || COMPILE_TEST)
>> +   help
>> + This selects driver for TI glue layer for Cadence UFS Host
>> + Controller IP.
>> +
>> + Selects this if you have TI platform with UFS controller.
>> + If unsure, say N.
>> +
>>  config SCSI_UFS_BSG
>> bool "Universal Flash Storage BSG device node"
>> depends on SCSI_UFSHCD
>> diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
>> index 2a9097939bcb..94c6c5d7334b 100644
>> --- a/drivers/scsi/ufs/Makefile
>> +++ b/drivers/scsi/ufs/Makefile
>> @@ -11,3 +11,4 @@ obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
>>  obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o
>>  obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o
>>  obj-$(CONFIG_SCSI_UFS_MEDIATEK) += ufs-mediatek.o
>> +obj-$(CONFIG_SCSI_UFS_TI_J721E) += ti-j721e-ufs.o
>> diff --git a/drivers/scsi/ufs/ti-j721e-ufs.c 
>> b/drivers/scsi/ufs/ti-j721e-ufs.c
>> new file mode 100644
>> index ..a653bf1902f3
>> --- /dev/null
>> +++ b/drivers/scsi/ufs/ti-j721e-ufs.c
>> @@ -0,0 +1,90 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +//
>> +// Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
>> +//
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define UFS_SS_CTRL0x4
>> +#define UFS_SS_RST_N_PCS   BIT(0)
>> +#define UFS_SS_CLK_26MHZ   BIT(4)
>> +
> These looks like vendor specific defines, if so, please add TI_* suffix.
> 

OK, will fix this in v2

>> +static int ti_j721e_ufs_probe(struct platform_device *pdev)
>> +{
>> +   struct device *dev = >dev;
>> +   unsigned long clk_rate;
>> +   void __iomem *regbase;
>> +   struct clk *clk;
>> +   u32 reg = 0;
>> +   int ret;
>> +
>> +   regbase = devm_platform_ioremap_resource(pdev, 0);
>> +   if (IS_ERR(regbase))
>> +   return PTR_ERR(regbase);
>> +
>> +   /* Select MPHY refclk frequency */
>> +   clk = devm_clk_get(dev, NULL);
>> +   if (IS_ERR(clk)) {
>> +   dev_err(dev, "Cannot claim MPHY clock.\n");
>> +   return PTR_ERR(clk);
>> +   }
> No need to enable MPHY clock? Moreover this clock belongs to MPHY and
> should be handled using generic PHY framework to do that.

pm_runtime_get_sync() call below will make sure all required clocks of
the module are enabled and also Cadence UFS controller/UFSHCD will
enable clocks explicitly. But what is needed here is to setup up wrapper
bit that informs MPHY module what is the frequency of its input clock
(whether its 19.2 MHz or 26MHz). Also this bit is not part of MPHY
address space so it cannot be modeled as PHY driver.

>> +   clk_rate = clk_get_rate(clk);
>> +   if (clk_rate == 2600)
>> +   reg |= UFS_SS_CLK_26MHZ;
>> +   devm_clk_put(dev, clk);
>> +
> Is this only needed to select one bit in UFS_SS_CLK_26MHz? if so, just
> have a DT property and get this selection from there.
> 

Yes its a single bit. But I don't think DT property is right way to do
especially when bit can be configured at runtime by querying clock
frequency using clk APIs.
In past I have received feedback from DT folks, to have DT describe only
generic properties (such as reg, interrupts, clocks etc) and handle most
other things in driver whenever possible.

>> +   pm_runtime_enable(dev);
>> +   ret = pm_runtime_get_sync(dev);
>> +   if (ret < 0) {
>> +   pm_runtime_put_noidle(dev);
>> +   return ret;
>> +   }
>> +
>> +   /*  Take UFS slave device out of reset */
>> +   reg |= UFS_SS_RST_N_PCS;
> What is the default value of UFS_SS_CLK_26MHZ bit above? Incase 26MHZ
> is not set, then what is default?

Default is of this bit is 0 => 19.2MHz (0 => 

Re: [PATCH 1/3] HID: logitech-hidpp: use devres to manage FF private data

2019-10-14 Thread Andrey Smirnov
On Sun, Oct 13, 2019 at 8:54 PM Sasha Levin  wrote:
>
> Hi,
>
> [This is an automated email]
>
> This commit has been processed because it contains a -stable tag.
> The stable tag indicates that it's relevant for the following trees: all
>
> The bot has tested the following trees: v5.3.5, v5.2.20, v4.19.78, v4.14.148, 
> v4.9.196, v4.4.196.
>
> v5.3.5: Build OK!
> v5.2.20: Build OK!
> v4.19.78: Failed to apply! Possible dependencies:
> 43cd97af70c65 ("HID: logitech: Stop setting drvdata to NULL on probe 
> failure and remove")
>
> v4.14.148: Failed to apply! Possible dependencies:
> 43cd97af70c65 ("HID: logitech: Stop setting drvdata to NULL on probe 
> failure and remove")
>
> v4.9.196: Failed to apply! Possible dependencies:
> 43cd97af70c65 ("HID: logitech: Stop setting drvdata to NULL on probe 
> failure and remove")
>
> v4.4.196: Failed to apply! Possible dependencies:
> 43cd97af70c65 ("HID: logitech: Stop setting drvdata to NULL on probe 
> failure and remove")
> 6c44b15e1c907 ("HID: logitech: check the return value of 
> create_singlethread_workqueue")
> 7bfd2927adcac ("HID: hid-logitech-hidpp: Add basic support for Logitech 
> G920")
> 7f4b49fef6ffb ("HID: hid-logitech-hidpp: Add range sysfs for Logitech 
> G920")
> af2e628d6be7a ("HID: logitech-hidpp: limit visibility of init/deinit 
> functions")
> ff21a635dd1a9 ("HID: logitech-hidpp: Force feedback support for the 
> Logitech G920")
>
>
> NOTE: The patch will not be queued to stable trees until it is upstream.
>
> How should we proceed with this patch?

Please ignore this series, since it will be superseded by upcoming v2

Thanks,
Andrey Smirnov


Re: [PATCH] perf cgroups: Don't rotate events for cgroups unnecessarily

2019-10-14 Thread Ganapatrao Kulkarni
Hi Peter,

On Wed, Sep 18, 2019 at 12:51 PM Ganapatrao Kulkarni  wrote:
>
> On Fri, Aug 23, 2019 at 6:33 PM Peter Zijlstra  wrote:
> >
> > On Fri, Aug 23, 2019 at 06:26:34PM +0530, Ganapatrao Kulkarni wrote:
> > > On Fri, Aug 23, 2019 at 5:29 PM Peter Zijlstra  
> > > wrote:
> > > > On Fri, Aug 23, 2019 at 04:13:46PM +0530, Ganapatrao Kulkarni wrote:
> > > >
> > > > > We are seeing regression with our uncore perf driver(Marvell's
> > > > > ThunderX2, ARM64 server platform) on 5.3-Rc1.
> > > > > After bisecting, it turned out to be this patch causing the issue.
> > > >
> > > > Funnily enough; the email you replied to didn't contain a patch.
> > >
> > > Hmm sorry, not sure why the patch is clipped-off, I see it in my inbox.
> >
> > Your email is in a random spot of the discussion for me. At least it was
> > fairly easy to find the related patch.
> >
> > > > > Test case:
> > > > > Load module and run perf for more than 4 events( we have 4 counters,
> > > > > event multiplexing takes place for more than 4 events), then unload
> > > > > module.
> > > > > With this sequence of testing, the system hangs(soft lockup) after 2
> > > > > or 3 iterations. Same test runs for hours on 5.2.
> > > > >
> > > > > while [ 1 ]
> > > > > do
> > > > > rmmod thunderx2_pmu
> > > > > modprobe thunderx2_pmu
> > > > > perf stat -a -e \
> > > > > uncore_dmc_0/cnt_cycles/,\
> > > > > uncore_dmc_0/data_transfers/,\
> > > > > uncore_dmc_0/read_txns/,\
> > > > > uncore_dmc_0/config=0xE/,\
> > > > > uncore_dmc_0/write_txns/ sleep 1
> > > > > sleep 2
> > > > > done
> > > >
> > > > Can you reproduce without the module load+unload? I don't think people
> > > > routinely unload modules.
> > >
> > > The issue wont happen, if module is not unloaded/reloaded.
> > > IMHO, this could be potential bug!
> >
> > Does the softlockup give a useful stacktrace? I don't have a thunderx2
> > so I cannot reproduce.
>
> Sorry for the late reply, below is the dump that i am getting, when i
> hit the softlockup.
> Any suggestions to debug this further?
>
> sequence of commands, which leads to this lockup,
> insmod thunderx2_pmu.ko
> perf stat -e \
> uncore_dmc_0/cnt_cycles/,\
> uncore_dmc_0/data_transfers/,\
> uncore_dmc_0/read_txns/,\
> uncore_dmc_0/config=0xE/,\
> uncore_dmc_0/write_txns/\
> rmmod thunderx2_pmu
> insmod thunderx2_pmu.ko
>
> root@SBR-26>~>> [ 1065.946772] watchdog: BUG: soft lockup - CPU#117
> stuck for 22s! [perf:5206]
> [ 1065.953722] Modules linked in: thunderx2_pmu(OE) nls_iso8859_1
> joydev input_leds bridge ipmi_ssif ipmi_devintf stp llc
> ipmi_msghandler sch_fq_codel ib_iser rdma_cm iw_cm ib_cm ib_core
> iscsi_tcp libiscsi_tcp
> libiscsi scsi_transport_iscsi ppdev lp parport ip_tables x_tables
> autofs4 btrfs zstd_compress raid10 raid456 async_raid6_recov
> async_memcpy async_pq async_xor async_tx xor xor_neon raid6_pq raid1
> raid0 multipat
> h linear aes_ce_blk hid_generic aes_ce_cipher usbhid uas usb_storage
> hid ast i2c_algo_bit drm_vram_helper ttm drm_kms_helper syscopyarea
> sysfillrect sysimgblt fb_sys_fops drm i40e i2c_smbus bnx2x
> crct10dif_ce g
> hash_ce e1000e sha2_ce mpt3sas nvme sha256_arm64 ptp ahci raid_class
> sha1_ce nvme_core scsi_transport_sas mdio libahci pps_core libcrc32c
> gpio_xlp i2c_xlp9xx aes_neon_bs aes_neon_blk crypto_simd cryptd
> aes_arm6
> 4 [last unloaded: thunderx2_pmu]
> [ 1066.029640] CPU: 117 PID: 5206 Comm: perf Tainted: G   OE
>   5.3.0+ #160
> [ 1066.037109] Hardware name: Cavium Inc. Saber/Saber, BIOS
> TX2-FW-Release-7.2-build_08-0-g14f8c5bf8a 12/18/2018
> [ 1066.047009] pstate: 2049 (nzCv daif +PAN -UAO)
> [ 1066.051799] pc : smp_call_function_single+0x198/0x1b0
> [ 1066.056838] lr : smp_call_function_single+0x16c/0x1b0
> [ 1066.061875] sp : fc00434cfc50
> [ 1066.065177] x29: fc00434cfc50 x28: 
> [ 1066.070475] x27: febed4d2d952 x26: d4d2d800
> [ 1066.075774] x25: fddf5da1e240 x24: 0001
> [ 1066.081073] x23: fc00434cfd38 x22: fc001026adb8
> [ 1066.086371] x21:  x20: fc0011843000
> [ 1066.091669] x19: fc00434cfca0 x18: 
> [ 1066.096968] x17:  x16: 
> [ 1066.102266] x15:  x14: 
> [ 1066.107564] x13:  x12: 0020
> [ 1066.112862] x11: 0101010101010101 x10: 7f7f7f7f7f7f7f7f
> [ 1066.118161] x9 :  x8 : febed44ec5e8
> [ 1066.123459] x7 :  x6 : fc00434cfca0
> [ 1066.128757] x5 : fc00434cfca0 x4 : 0001
> [ 1066.134055] x3 : fc00434cfcb8 x2 : 
> [ 1066.139353] x1 : 0003 x0 : 
> [ 1066.144652] Call trace:
> [ 1066.147088]  smp_call_function_single+0x198/0x1b0
> [ 1066.151784]  perf_install_in_context+0x1b4/0x1d8
> [ 1066.156394]  __se_sys_perf_event_open+0x634/0xa68
> [ 1066.161089]  __arm64_sys_perf_event_open+0x1c/0x28
> [ 

Re: [PATCH RESEND 1/1] vfs: Really check for inode ptr in lookup_fast

2019-10-14 Thread Ritesh Harjani

ping!!

On 9/27/19 10:12 AM, Ritesh Harjani wrote:

d_is_negative can race with d_instantiate_new()
-> __d_set_inode_and_type().
For e.g. in use cases where Thread-1 is creating
symlink (doing d_instantiate_new()) & Thread-2 is doing
cat of that symlink while doing lookup_fast (via REF-walk-
one such case is, when ->permission returns -ECHILD).

During this race if __d_set_and_inode_type() does out-of-order
execution and set the dentry->d_flags before setting
dentry->inode, then it can result into following kernel panic.

This change fixes the issue by directly checking for inode.

E.g. kernel panic, since inode was NULL.
trailing_symlink() -> may_follow_link() -> inode->i_uid.
Issue signature:-
   [NIP  : trailing_symlink+80]
   [LR   : trailing_symlink+1092]
   #4 [c0198069bb70] trailing_symlink at c04bae60  (unreliable)
   #5 [c0198069bc00] path_openat at c04bdd14
   #6 [c0198069bc90] do_filp_open at c04c0274
   #7 [c0198069bdb0] do_sys_open at c049b248
   #8 [c0198069be30] system_call at c000b388

Sequence of events:-
Thread-2(Comm: ln) Thread-1(Comm: cat)

dentry = __d_lookup() //nonRCU

__d_set_and_inode_type() (Out-of-order execution)
 flags = READ_ONCE(dentry->d_flags);
 flags &= ~(DCACHE_ENTRY_TYPE | DCACHE_FALLTHRU);
 flags |= type_flags;
 WRITE_ONCE(dentry->d_flags, flags);

if (unlikely(d_is_negative()) // fails
   {}
// since d_flags is already updated in
// Thread-2 in parallel but inode
// not yet set.
// d_is_negative returns false

*inode = d_backing_inode(path->dentry);
// means inode is still NULL

 dentry->d_inode = inode;

trailing_symlink()
may_follow_link()
inode = nd->link_inode;
// nd->link_inode = NULL
//Then it crashes while
//doing inode->i_uid

Reported-by: Guang Yuan Wu 
Tested-by: Guang Yuan Wu 
Acked-by: Jeff Layton 
Signed-off-by: Ritesh Harjani 
---
  fs/namei.c | 16 +++-
  1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/namei.c b/fs/namei.c
index 671c3c1a3425..7c5337cddebd 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1617,7 +1617,21 @@ static int lookup_fast(struct nameidata *nd,
dput(dentry);
return status;
}
-   if (unlikely(d_is_negative(dentry))) {
+
+   /*
+* Caution: d_is_negative() can race with
+* __d_set_inode_and_type().
+* For e.g. in use cases where Thread-1 is creating
+* symlink (doing d_instantiate_new()) & Thread-2 is doing
+* cat of that symlink and falling here (via Ref-walk) while
+* doing lookup_fast (one such case is when ->permission
+* returns -ECHILD).
+* Now if __d_set_inode_and_type() does out-of-order execution
+* i.e. it first sets the dentry->d_flags & then dentry->inode
+* then it can result into inode being NULL, causing panic later.
+* Hence directly check if inode is NULL here.
+*/
+   if (unlikely(d_really_is_negative(dentry))) {
dput(dentry);
return -ENOENT;
}





Re: [PATCH] MIPS: Loongson: Make default kernel log buffer size as 128KB for Loongson3

2019-10-14 Thread Tiezhu Yang

On 10/15/2019 11:36 AM, Huacai Chen wrote:

On Tue, Oct 15, 2019 at 10:12 AM Tiezhu Yang  wrote:

When I update kernel with loongson3_defconfig based on the Loongson 3A3000
platform, then using dmesg command to show kernel ring buffer, the initial
kernel messages have disappeared due to the log buffer is too small, it is
better to change the default kernel log buffer size from 16KB to 128KB.

Signed-off-by: Tiezhu Yang 
---
  arch/mips/configs/loongson3_defconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/configs/loongson3_defconfig 
b/arch/mips/configs/loongson3_defconfig
index 90ee008..3aa2201 100644
--- a/arch/mips/configs/loongson3_defconfig
+++ b/arch/mips/configs/loongson3_defconfig
@@ -12,7 +12,7 @@ CONFIG_TASKSTATS=y
  CONFIG_TASK_DELAY_ACCT=y
  CONFIG_TASK_XACCT=y
  CONFIG_TASK_IO_ACCOUNTING=y
-CONFIG_LOG_BUF_SHIFT=14
+CONFIG_LOG_BUF_SHIFT=17

Hi, Tiezhu,

Why you choose 128KB but not 64KB or 256KB? I found 64KB is enough for
our cases. And if you really need more, I think 256KB could be better
because there are many platforms choose 256KB.


Hi Huacai,

Thanks for your reply and suggestion, I will send a v2 patch.

Thanks,

Tiezhu Yang



Huacai


  CONFIG_MEMCG=y
  CONFIG_MEMCG_SWAP=y
  CONFIG_BLK_CGROUP=y
--
2.1.0






Re: [RFC][PATCH v2 4/5] dt-bindings: usb: dwc3: of-simple: add compatible for HiSi

2019-10-14 Thread John Stultz
On Fri, Oct 11, 2019 at 8:51 AM Rob Herring  wrote:
>
> On Mon, Oct 07, 2019 at 04:00:24PM -0700, John Stultz wrote:
> > On Mon, Oct 7, 2019 at 2:11 PM Rob Herring  wrote:
> > >
> > > On Mon, Oct 7, 2019 at 2:07 PM John Stultz  wrote:
> > > >
> > > > On Mon, Oct 7, 2019 at 11:38 AM Rob Herring  wrote:
> > > > >
> > > > > On Mon, Oct 7, 2019 at 12:56 PM John Stultz  
> > > > > wrote:
> > > > > >
> > > > > > Add necessary compatible flag for HiSi's DWC3 so
> > > > > > dwc3-of-simple will probe.
> > > > > >
> > > > > > Cc: Greg Kroah-Hartman 
> > > > > > Cc: Felipe Balbi 
> > > > > > Cc: Andy Shevchenko 
> > > > > > Cc: Rob Herring 
> > > > > > Cc: Mark Rutland 
> > > > > > Cc: Yu Chen 
> > > > > > Cc: Matthias Brugger 
> > > > > > Cc: Chunfeng Yun 
> > > > > > Cc: linux-...@vger.kernel.org
> > > > > > Cc: devicet...@vger.kernel.org
> > > > > > Signed-off-by: John Stultz 
> > > > > > ---
> > > > > > v2: Tweaked clock names as clk_usb3phy_ref didn't seem right.
> > > > > > ---
> > > > > >  .../devicetree/bindings/usb/hisi,dwc3.txt | 52 
> > > > > > +++
> > > > > >  1 file changed, 52 insertions(+)
> > > > > >  create mode 100644 
> > > > > > Documentation/devicetree/bindings/usb/hisi,dwc3.txt
> > > > >
> > > > > Can you make this a schema.
> > > >
> > > > Sorry, I'm not sure exactly what you're asking. I'm guessing from
> > > > grepping around you want the bindings in yaml instead (I see a few
> > > > examples)?
> > >
> > > Yes.
> > >
> > > > Is there some pointer to documentation? The
> > > > Documentation/devicetree/bindings/writing-bindings.txt file doesn't
> > > > seem to say much on it.
> > >
> > > You mean Documentation/devicetree/writing-schemas.rst? There's that
> > > and Documentation/devicetree/bindings/example-schema.yaml which has a
> > > bunch of annotations on what each part means.
> >
> > Ah! Sorry for missing that. Thanks for the pointer, though I may get
> > away with dropping this one.
> >
> > > > > If it's only clocks and resets for the wrapper node, just make this
> > > > > all one node.
> > > >
> > > > Just to make sure I'm following, you're suggesting I put all the
> > > > clocks/resets in the dwc3 node (renamed to usb for the node name) and
> > > > not add the wrapper?
> > >
> > > Yes.
> > >
> > > > I'll have to see if that's possible. The generic dwc3 binding wants 3
> > > > clocks, but I only have two in the code I've worked with (similarly it
> > > > seems to only want two resets, not 4) so I'll have to see if I can
> > > > figure out how to adapt that.
> > >
> > > Possible since commit fe8abf332b8f ("usb: dwc3: support clocks and
> > > resets for DWC3 core").
> >
> > Ok. It *seems* like I can get it working with the existing binding
> > then. There's a little funkiness with the core expecting three clocks
> > while I only have two (currently I'm duplicating the "bus_early" clk
> > for "suspend". Is there a preferred way to do this sort of hack?), and
> > I'm a little worried that only the first reset is being used (instead
> > of the 4 specified), but it seems to work so far.
>
> I would assume that you simply don't know how the 'suspend' clock is
> connected rather than you don't have one. But that's maybe not a
> problem you can fix.
>
> I would make dwc3 use devm_clk_bulk_get_all and allow for less than 3
> clocks. And do a similar change for resets.

So got a chance to start implementing this and it seems like it will
work. That said, it feels like I'm duplicating logic already in the
dwc-of-simple.c implementation (which already handles arbitrary clks
and resets), particularly if I try to implement the device specific
need_reset quirk used by HiKey960 (and rk3399).

Do you feel having that logic copied is worth avoiding the extra
bindings? Or is it too duplicative?

thanks
-john


[PATCH 1/2] mm, frontswap: Fix frontswap_map issue with THP

2019-10-14 Thread Hui Zhu
Shrink will try to use frontswap interface store the THP as a normal
page in __frontswap_store:
if (ret == 0) {
__frontswap_set(sis, offset);
inc_frontswap_succ_stores();
} else {
It should set all bits with THP.

This commit set all bits with THP.

Signed-off-by: Hui Zhu 
---
 mm/frontswap.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/frontswap.c b/mm/frontswap.c
index 60bb20e..f07ea63 100644
--- a/mm/frontswap.c
+++ b/mm/frontswap.c
@@ -274,8 +274,12 @@ int __frontswap_store(struct page *page)
break;
}
if (ret == 0) {
-   __frontswap_set(sis, offset);
-   inc_frontswap_succ_stores();
+   int i, nr = hpage_nr_pages(page);
+
+   for (i = 0; i < nr; i++) {
+   __frontswap_set(sis, offset + i);
+   inc_frontswap_succ_stores();
+   }
} else {
inc_frontswap_failed_stores();
}
-- 
2.7.4



  1   2   3   4   5   6   7   8   9   >