[PATCH v7 12/12] perf tests: implement Zstd comp/decomp integration test

2019-03-11 Thread Alexey Budankov


Implemented basic integration test for Zstd based trace
compression/decompression in record and report modes.

Signed-off-by: Alexey Budankov 
---
 .../tests/shell/record+zstd_comp_decomp.sh| 28 +++
 1 file changed, 28 insertions(+)
 create mode 100755 tools/perf/tests/shell/record+zstd_comp_decomp.sh

diff --git a/tools/perf/tests/shell/record+zstd_comp_decomp.sh 
b/tools/perf/tests/shell/record+zstd_comp_decomp.sh
new file mode 100755
index ..5cb2ab8e2112
--- /dev/null
+++ b/tools/perf/tests/shell/record+zstd_comp_decomp.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+# record trace Zstd compression/decompression
+
+trace_file=$(mktemp /tmp/perf.data.XXX)
+perf_tool=perf
+output=/dev/null
+
+skip_if_no_z_record() {
+   $perf_tool record -h 2>&1 | grep '\-z, \-\-compression\-level '
+}
+
+collect_z_record() {
+   echo "Collecting compressed record trace file:"
+   $perf_tool record -o $trace_file -a -z 1 -F 25000 -e cycles -- \
+   dd count=2000 if=/dev/random of=/dev/null > $output 2>&1
+}
+
+check_compressed_stats() {
+   echo "Checking compressed events stats:"
+   $perf_tool report -i $trace_file --header --stats | \
+   grep -E "(# compressed : Zstd,)|(COMPRESSED events:)" > $output 
2>&1
+}
+
+skip_if_no_z_record || exit 2
+collect_z_record && check_compressed_stats
+err=$?
+rm -f $trace_file
+exit $err
-- 
2.20.1



[PATCH v7 11/12] perf inject: enable COMPRESSED records decompression

2019-03-11 Thread Alexey Budankov


Initialized decompression part of Zstd based API so COMPRESSED records
would be decompressed into the resulting output data file.

Signed-off-by: Alexey Budankov 
---
 tools/perf/builtin-inject.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 24086b7f1b14..8e0e06d3edfc 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -837,6 +837,9 @@ int cmd_inject(int argc, const char **argv)
if (inject.session == NULL)
return -1;
 
+   if (zstd_init(&(inject.session->zstd_data), 0) < 0)
+   pr_warning("Decompression initialization failed.\n");
+
if (inject.build_ids) {
/*
 * to make sure the mmap records are ordered correctly
@@ -867,6 +870,7 @@ int cmd_inject(int argc, const char **argv)
ret = __cmd_inject();
 
 out_delete:
+   zstd_fini(&(inject.session->zstd_data));
perf_session__delete(inject.session);
return ret;
 }
-- 
2.20.1



[PATCH v7 10/12] perf report: implement record trace decompression

2019-03-11 Thread Alexey Budankov


zstd_init(, comp_level = 0) initializes decompression part of API only
that now consists of zstd_decompress_stream() function.

Trace frames containing PERF_RECORD_COMPRESSED records are decompressed
using zstd_decompress_stream() function into a linked list of mmaped 
memory regions of mmap_comp_len size (struct decomp).

After decompression of one COMPRESSED record its content is iterated and
fetched for usual processing. The mmaped memory regions with decompressed
events are kept in the linked list till the tool process termination.

When dumping raw trace (e.g., perf report -D --header) file offsets of
events from compressed records are printed as zero.

Signed-off-by: Alexey Budankov 
---
 tools/perf/builtin-report.c |   5 +-
 tools/perf/util/compress.h  |   4 ++
 tools/perf/util/session.c   | 124 +++-
 tools/perf/util/session.h   |  10 +++
 tools/perf/util/tool.h  |   2 +
 tools/perf/util/zstd.c  |  48 ++
 6 files changed, 191 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 05c8dd41106c..66aceca49312 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1258,6 +1258,9 @@ int cmd_report(int argc, const char **argv)
if (session == NULL)
return -1;
 
+   if (zstd_init(&(session->zstd_data), 0) < 0)
+   pr_warning("Decompression initialization failed. Reported data 
may be incomplete.\n");
+
if (report.queue_size) {
ordered_events__set_alloc_size(>ordered_events,
   report.queue_size);
@@ -1448,7 +1451,7 @@ int cmd_report(int argc, const char **argv)
 error:
if (report.ptime_range)
zfree(_range);
-
+   zstd_fini(&(session->zstd_data));
perf_session__delete(session);
return ret;
 }
diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h
index e0987616db94..4f6672770ebb 100644
--- a/tools/perf/util/compress.h
+++ b/tools/perf/util/compress.h
@@ -20,6 +20,7 @@ bool lzma_is_compressed(const char *input);
 struct zstd_data {
 #ifdef HAVE_ZSTD_SUPPORT
ZSTD_CStream*cstream;
+   ZSTD_DStream*dstream;
 #endif
 };
 
@@ -30,4 +31,7 @@ size_t zstd_compress_stream_to_records(struct zstd_data *data,
void *dst, size_t dst_size, void *src, size_t src_size, size_t 
max_record_size,
size_t process_header(void *record, size_t increment));
 
+size_t zstd_decompress_stream(struct zstd_data *data,
+   void *src, size_t src_size, void *dst, size_t dst_size);
+
 #endif /* PERF_COMPRESS_H */
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 0ec34227bd60..a2e4f1202fe4 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -29,6 +29,67 @@
 #include "stat.h"
 #include "arch/common.h"
 
+#ifdef HAVE_ZSTD_SUPPORT
+static int perf_session__process_compressed_event(struct perf_session *session,
+   union perf_event *event, u64 
file_offset)
+{
+   void *src;
+   size_t decomp_size, src_size;
+   u64 decomp_last_rem = 0;
+   size_t decomp_len = session->header.env.comp_mmap_len;
+   struct decomp *decomp, *decomp_last = session->decomp_last;
+
+   decomp = mmap(NULL, sizeof(struct decomp) + decomp_len, 
PROT_READ|PROT_WRITE,
+ MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+   if (decomp == MAP_FAILED) {
+   pr_err("Couldn't allocate memory for decompression\n");
+   return -1;
+   }
+
+   decomp->file_pos = file_offset;
+   decomp->head = 0;
+
+   if (decomp_last) {
+   decomp_last_rem = decomp_last->size - decomp_last->head;
+   memcpy(decomp->data, &(decomp_last->data[decomp_last->head]), 
decomp_last_rem);
+   decomp->size = decomp_last_rem;
+   }
+
+   src = (void *)event + sizeof(struct compressed_event);
+   src_size = event->pack.header.size - sizeof(struct compressed_event);
+
+   decomp_size = zstd_decompress_stream(&(session->zstd_data), src, 
src_size,
+   &(decomp->data[decomp_last_rem]), decomp_len - 
decomp_last_rem);
+   if (!decomp_size) {
+   munmap(decomp, sizeof(struct decomp) + decomp_len);
+   pr_err("Couldn't decompress data\n");
+   return -1;
+   }
+
+   decomp->size += decomp_size;
+
+   if (session->decomp == NULL) {
+   session->decomp = decomp;
+   session->decomp_last = decomp;
+   } else {
+   session->decomp_last->next = decomp;
+   session->decomp_last = decomp;
+   }
+
+   pr_debug("decomp (B): %ld to %ld\n", src_size, decomp_size);
+
+   return 0;
+}
+#else /* !HAVE_ZSTD_SUPPORT */
+static int perf_session__process_compressed_event(struct perf_session *session 
__maybe_unused,
+   union 

kernel 5.0 blk_clear_pm_only triggers a warning during resume

2019-03-11 Thread Jisheng Zhang
Hi,

kernel version: 5.0

I got below warning during resume:

[  673.65] sd 0:0:0:0: [sda] Starting disk
[  673.658899] WARNING: CPU: 3 PID: 1039 at blk_clear_pm_only+0x2a/0x30
[  673.658902] CPU: 3 PID: 1039 Comm: kworker/u8:49 Not tainted 5.0.0+ #1
[  673.658902] sd 2:0:0:0: [sdb] Starting disk
[  673.658903] Hardware name: LENOVO 4180F42/4180F42, BIOS 83ET75WW (1.45 ) 
05/10/2013
[  673.658906] Workqueue: events_unbound async_run_entry_fn
[  673.658909] RIP: 0010:blk_clear_pm_only+0x2a/0x30
[  673.658911] Code: b8 ff ff ff ff f0 0f c1 87 80 00 00 00 83 e8 01 78 18 74 
01 c3 48 81 c7 58 05 00 00 31 c9 31 d2 be 03 00 00 00 e9 36 97 e2 ff <0f> 0b c3 
0f 1f 00 48 81 c7 90 00 00 00 e9 04 01 3a 00 0f 1f 40 00
[  673.658911] RSP: :8881115a7e48 EFLAGS: 00010297
[  673.658913] RAX:  RBX: 888118d42800 RCX: 8881194c9a00
[  673.658914] RDX: 888118ab1a00 RSI:  RDI: 888117e7
[  673.658915] RBP: 888118d42f90 R08: 0004 R09: 0001f900
[  673.658915] R10: 45698a8e R11: 0010 R12: 888119421000
[  673.658916] R13:  R14: 88800030ea80 R15: 088811942100
[  673.658918] FS:  () GS:88811a18() 
knlGS:
[  673.658918] CS:  0010 DS:  ES:  CR0: 80050033
[  673.658919] CR2:  CR3: 0200c001 CR4: 000606e0
[  673.658920] Call Trace:
[  673.658924]  ? scsi_device_resume+0x28/0x50
[  673.658926]  ? scsi_dev_type_resume+0x2b/0x80
[  673.658927]  ? async_run_entry_fn+0x2c/0xd0
[  673.658930]  ? process_one_work+0x1f0/0x3f0
[  673.658932]  ? worker_thread+0x28/0x3c0
[  673.658933]  ? process_one_work+0x3f0/0x3f0
[  673.658935]  ? kthread+0x10c/0x130
[  673.658936]  ? __kthread_create_on_node+0x150/0x150
[  673.658938]  ? ret_from_fork+0x1f/0x30
[  673.658940] ---[ end trace ce18772de33e283e ]---


I notice that commit 388b4e6a00bb3 ("scsi: core: Avoid that system resume
triggers a kernel warning") tried to fix the warning in the same code path
perhaps, it isn't enough.

Thanks


Re: [PATCH v9 1/9] bitops: Introduce the for_each_set_clump8 macro

2019-03-11 Thread Masahiro Yamada
On Fri, Mar 8, 2019 at 5:57 PM William Breathitt Gray
 wrote:
>
> On Fri, Mar 08, 2019 at 09:31:00AM +0100, Linus Walleij wrote:
> > On Sun, Mar 3, 2019 at 8:47 AM William Breathitt Gray
> >  wrote:
> >
> > > This macro iterates for each 8-bit group of bits (clump) with set bits,
> > > within a bitmap memory region. For each iteration, "start" is set to the
> > > bit offset of the found clump, while the respective clump value is
> > > stored to the location pointed by "clump". Additionally, the
> > > bitmap_get_value8 and bitmap_set_value8 functions are introduced to
> > > respectively get and set an 8-bit value in a bitmap memory region.
> > >
> > > Suggested-by: Andy Shevchenko 
> > > Suggested-by: Rasmus Villemoes 
> > > Cc: Arnd Bergmann 
> > > Cc: Andrew Morton 
> > > Reviewed-by: Andy Shevchenko 
> > > Reviewed-by: Linus Walleij 
> > > Signed-off-by: William Breathitt Gray 
> >
> > Andrew: would you be OK with this being merged in v5.1?
> >
> > If we need to move the code to drivers/gpio that's OK (though
> > I think it's generally useful) but I need to know to proceed with
> > the William's nice optimization of these drivers.
> >
> > Yours,
> > Linus Walleij
>
> I was waiting on Andy to suggest some examples out of the GPIO realm,
> but he may be under a heavy workload right so I decided to do a quick
> search for one.
>
> In drivers/of/unittest.c, there is loop across a bitmap in the
> of_unittest_destroy_tracked_overlays function:
>
> for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) {
> if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id)))
> continue;
>
> This section of code is checking each bit individually, and skipping if
> that bit is not set. This looping can be optimized by using the
> for_each_set_clump8 macro


Probably no.


I see this comment before the loop.
/* remove in reverse order */


Also, the unittest code handles per-bit
whereas your helper does per-byte.





> to skip clumps of nonset bits (not to mention
> make the logic of the code much simpler and easier to follow by reducing
> the code to a single line):
>
> for_each_set_clump8(id, clump, overlay_id_bits, 
> MAX_UNITTEST_OVERLAYS-1)
>
> The for_each_set_clump8 macro is not specific to the GPIO subsystem; I
> just happen to use it in these GPIO drivers simply because I am most
> familar with this section of the kernel (it's where most of my
> contributions occur afterall).
>
> Consider this, if I am able to find a use for this macro outside of the
> GPIO subsystem within a matter minutes, then there must be some benefit
> in allowing the rest of the kernel to use the for_each_set_clump8 macro.
> So let's put it in bitops.h rather than restrict it to just the GPIO
> subsystem.


If we do not find useful cases in other subsystem,
this patch set looks over-engineering to me.






> William Breathitt Gray


--
Best Regards
Masahiro Yamada


[PATCH v7 09/12] perf record: implement -z,--compression_level=n option

2019-03-11 Thread Alexey Budankov


Implemented -z,--compression_level=n option that enables compression
of mmaped kernel data buffers content in runtime during perf record
mode collection.

Compression overhead has been measured for serial and AIO streaming
when profiling matrix multiplication workload:

-
| SERIAL  | AIO-1   |
|
|-z | OVH(x) | ratio(x) size(MiB) | OVH(x) | ratio(x) size(MiB) |
|---|
| 0 | 1,00   | 1,000179,424   | 1,00   | 1,000187,527   |
| 1 | 1,04   | 8,427181,148   | 1,01   | 8,474188,562   |
| 2 | 1,07   | 8,055186,953   | 1,03   | 7,912191,773   |
| 3 | 1,04   | 8,283181,908   | 1,03   | 8,220191,078   |
| 5 | 1,09   | 8,101187,705   | 1,05   | 7,780190,065   |
| 8 | 1,05   | 9,217179,191   | 1,12   | 6,111193,024   |
-

OVH = (Execution time with -z N) / (Execution time with -z 0)

ratio - compression ratio
size  - number of bytes that was compressed

size ~= trace size x ratio

Signed-off-by: Alexey Budankov 
---
 tools/perf/Documentation/perf-record.txt | 5 +
 tools/perf/builtin-record.c  | 6 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index d1e6c1fd7387..632502b1f335 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -472,6 +472,11 @@ Also at some cases executing less trace write syscalls 
with bigger data size can
 shorter than executing more trace write syscalls with smaller data size thus 
lowering
 runtime profiling overhead.
 
+-z::
+--compression-level=n::
+Produce compressed trace using specified level n (no compression: 0 - default,
+fastest compression: 1, smallest trace: 22)
+
 --all-kernel::
 Configure all used events to run in kernel space.
 
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 47e0abe22192..9f1bba6d4331 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -346,7 +346,7 @@ static void record__aio_mmap_read_sync(struct record *rec)
struct perf_evlist *evlist = rec->evlist;
struct perf_mmap *maps = evlist->mmap;
 
-   if (!rec->opts.nr_cblocks)
+   if (!record__aio_enabled(rec))
return;
 
for (i = 0; i < evlist->nr_mmaps; i++) {
@@ -2166,6 +2166,10 @@ static struct option __record_options[] = {
OPT_CALLBACK(0, "affinity", , "node|cpu",
 "Set affinity mask of trace reading thread to NUMA node 
cpu mask or cpu of processed mmap buffer",
 record__parse_affinity),
+#ifdef HAVE_ZSTD_SUPPORT
+   OPT_UINTEGER('z', "compression-level", _level,
+"Produce compressed trace using specified level (default: 
0, fastest: 1, smallest: 22)"),
+#endif
OPT_END()
 };
 
-- 
2.20.1



[PATCH v9 perf,bpf 02/15] bpf: libbpf: introduce bpf_program__get_prog_info_linear()

2019-03-11 Thread Song Liu
Currently, bpf_prog_info includes 9 arrays. The user has the option to
fetch any combination of these arrays. However, this requires a lot of
handling of these arrays. This work becomes more tricky when we need to
store bpf_prog_info to a file, because these arrays are allocated
independently.

This patch introduces struct bpf_prog_info_linear, which stores arrays
of bpf_prog_info in continues memory. Helper functions are introduced
to unify the work to get different information of bpf_prog_info.
Specifically, bpf_program__get_prog_info_linear() allows the user to
select which arrays to fetch, and handles details for the user.

Plesae see the comments before enum bpf_prog_info_array for more details
and examples.

Cc: Daniel Borkmann 
Cc: Alexei Starovoitov 
Signed-off-by: Song Liu 
---
 tools/lib/bpf/libbpf.c   | 251 +++
 tools/lib/bpf/libbpf.h   |  63 ++
 tools/lib/bpf/libbpf.map |   3 +
 3 files changed, 317 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index d5b830d60601..98ec9a8cd7af 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -112,6 +112,11 @@ void libbpf_print(enum libbpf_print_level level, const 
char *format, ...)
 # define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
 #endif
 
+static inline __u64 ptr_to_u64(const void *ptr)
+{
+   return (__u64) (unsigned long) ptr;
+}
+
 struct bpf_capabilities {
/* v4.14: kernel support for program & map names. */
__u32 name:1;
@@ -2999,3 +3004,249 @@ bpf_perf_event_read_simple(void *mmap_mem, size_t 
mmap_size, size_t page_size,
ring_buffer_write_tail(header, data_tail);
return ret;
 }
+
+struct bpf_prog_info_array_desc {
+   int array_offset;   /* e.g. offset of jited_prog_insns */
+   int count_offset;   /* e.g. offset of jited_prog_len */
+   int size_offset;/* > 0: offset of rec size,
+* < 0: fix size of -size_offset
+*/
+};
+
+static struct bpf_prog_info_array_desc bpf_prog_info_array_desc[] = {
+   [BPF_PROG_INFO_JITED_INSNS] = {
+   offsetof(struct bpf_prog_info, jited_prog_insns),
+   offsetof(struct bpf_prog_info, jited_prog_len),
+   -1,
+   },
+   [BPF_PROG_INFO_XLATED_INSNS] = {
+   offsetof(struct bpf_prog_info, xlated_prog_insns),
+   offsetof(struct bpf_prog_info, xlated_prog_len),
+   -1,
+   },
+   [BPF_PROG_INFO_MAP_IDS] = {
+   offsetof(struct bpf_prog_info, map_ids),
+   offsetof(struct bpf_prog_info, nr_map_ids),
+   -(int)sizeof(__u32),
+   },
+   [BPF_PROG_INFO_JITED_KSYMS] = {
+   offsetof(struct bpf_prog_info, jited_ksyms),
+   offsetof(struct bpf_prog_info, nr_jited_ksyms),
+   -(int)sizeof(__u64),
+   },
+   [BPF_PROG_INFO_JITED_FUNC_LENS] = {
+   offsetof(struct bpf_prog_info, jited_func_lens),
+   offsetof(struct bpf_prog_info, nr_jited_func_lens),
+   -(int)sizeof(__u32),
+   },
+   [BPF_PROG_INFO_FUNC_INFO] = {
+   offsetof(struct bpf_prog_info, func_info),
+   offsetof(struct bpf_prog_info, nr_func_info),
+   offsetof(struct bpf_prog_info, func_info_rec_size),
+   },
+   [BPF_PROG_INFO_LINE_INFO] = {
+   offsetof(struct bpf_prog_info, line_info),
+   offsetof(struct bpf_prog_info, nr_line_info),
+   offsetof(struct bpf_prog_info, line_info_rec_size),
+   },
+   [BPF_PROG_INFO_JITED_LINE_INFO] = {
+   offsetof(struct bpf_prog_info, jited_line_info),
+   offsetof(struct bpf_prog_info, nr_jited_line_info),
+   offsetof(struct bpf_prog_info, jited_line_info_rec_size),
+   },
+   [BPF_PROG_INFO_PROG_TAGS] = {
+   offsetof(struct bpf_prog_info, prog_tags),
+   offsetof(struct bpf_prog_info, nr_prog_tags),
+   -(int)sizeof(__u8) * BPF_TAG_SIZE,
+   },
+
+};
+
+static __u32 bpf_prog_info_read_offset_u32(struct bpf_prog_info *info, int 
offset)
+{
+   __u32 *array = (__u32 *)info;
+
+   if (offset >= 0)
+   return array[offset / sizeof(__u32)];
+   return -(int)offset;
+}
+
+static __u64 bpf_prog_info_read_offset_u64(struct bpf_prog_info *info, int 
offset)
+{
+   __u64 *array = (__u64 *)info;
+
+   if (offset >= 0)
+   return array[offset / sizeof(__u64)];
+   return -(int)offset;
+}
+
+static void bpf_prog_info_set_offset_u32(struct bpf_prog_info *info, int 
offset,
+__u32 val)
+{
+   __u32 *array = (__u32 *)info;
+
+   if (offset >= 0)
+   array[offset / sizeof(__u32)] = val;
+}
+
+static void bpf_prog_info_set_offset_u64(struct bpf_prog_info *info, int 
offset,
+__u64 val)
+{
+   

[PATCH v9 perf,bpf 04/15] perf, bpf: synthesize bpf events with bpf_program__get_prog_info_linear()

2019-03-11 Thread Song Liu
With bpf_program__get_prog_info_linear, we can simplify the logic that
synthesizes bpf events.

This patch doesn't change the behavior of the code.

Signed-off-by: Song Liu 
---
 tools/perf/util/bpf-event.c | 118 
 1 file changed, 40 insertions(+), 78 deletions(-)

diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index ea012b735a37..e9d9854be506 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -3,7 +3,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include "bpf-event.h"
 #include "debug.h"
 #include "symbol.h"
@@ -49,99 +51,62 @@ static int perf_event__synthesize_one_bpf_prog(struct 
perf_tool *tool,
 {
struct ksymbol_event *ksymbol_event = >ksymbol_event;
struct bpf_event *bpf_event = >bpf_event;
-   u32 sub_prog_cnt, i, func_info_rec_size = 0;
-   u8 (*prog_tags)[BPF_TAG_SIZE] = NULL;
-   struct bpf_prog_info info = { .type = 0, };
-   u32 info_len = sizeof(info);
-   void *func_infos = NULL;
-   u64 *prog_addrs = NULL;
+   struct bpf_prog_info_linear *info_linear;
+   struct bpf_prog_info *info;
struct btf *btf = NULL;
-   u32 *prog_lens = NULL;
bool has_btf = false;
-   char errbuf[512];
+   u32 sub_prog_cnt, i;
int err = 0;
+   u64 arrays;
 
-   /* Call bpf_obj_get_info_by_fd() to get sizes of arrays */
-   err = bpf_obj_get_info_by_fd(fd, , _len);
+   arrays = 1UL << BPF_PROG_INFO_JITED_KSYMS;
+   arrays |= 1UL << BPF_PROG_INFO_JITED_FUNC_LENS;
+   arrays |= 1UL << BPF_PROG_INFO_FUNC_INFO;
+   arrays |= 1UL << BPF_PROG_INFO_PROG_TAGS;
 
-   if (err) {
-   pr_debug("%s: failed to get BPF program info: %s, aborting\n",
-__func__, str_error_r(errno, errbuf, sizeof(errbuf)));
+   info_linear = bpf_program__get_prog_info_linear(fd, arrays);
+   if (IS_ERR_OR_NULL(info_linear)) {
+   info_linear = NULL;
+   pr_debug("%s: failed to get BPF program info. aborting\n", 
__func__);
return -1;
}
-   if (info_len < offsetof(struct bpf_prog_info, prog_tags)) {
+
+   if (info_linear->info_len < offsetof(struct bpf_prog_info, prog_tags)) {
pr_debug("%s: the kernel is too old, aborting\n", __func__);
return -2;
}
 
+   info = _linear->info;
+
/* number of ksyms, func_lengths, and tags should match */
-   sub_prog_cnt = info.nr_jited_ksyms;
-   if (sub_prog_cnt != info.nr_prog_tags ||
-   sub_prog_cnt != info.nr_jited_func_lens)
+   sub_prog_cnt = info->nr_jited_ksyms;
+   if (sub_prog_cnt != info->nr_prog_tags ||
+   sub_prog_cnt != info->nr_jited_func_lens)
return -1;
 
/* check BTF func info support */
-   if (info.btf_id && info.nr_func_info && info.func_info_rec_size) {
+   if (info->btf_id && info->nr_func_info && info->func_info_rec_size) {
/* btf func info number should be same as sub_prog_cnt */
-   if (sub_prog_cnt != info.nr_func_info) {
+   if (sub_prog_cnt != info->nr_func_info) {
pr_debug("%s: mismatch in BPF sub program count and BTF 
function info count, aborting\n", __func__);
-   return -1;
-   }
-   if (btf__get_from_id(info.btf_id, )) {
-   pr_debug("%s: failed to get BTF of id %u, aborting\n", 
__func__, info.btf_id);
-   return -1;
+   err = -1;
+   goto out;
}
-   func_info_rec_size = info.func_info_rec_size;
-   func_infos = calloc(sub_prog_cnt, func_info_rec_size);
-   if (!func_infos) {
-   pr_debug("%s: failed to allocate memory for func_infos, 
aborting\n", __func__);
-   return -1;
+   if (btf__get_from_id(info->btf_id, )) {
+   pr_debug("%s: failed to get BTF of id %u, aborting\n", 
__func__, info->btf_id);
+   err = -1;
+   btf = NULL;
+   goto out;
}
has_btf = true;
}
 
-   /*
-* We need address, length, and tag for each sub program.
-* Allocate memory and call bpf_obj_get_info_by_fd() again
-*/
-   prog_addrs = calloc(sub_prog_cnt, sizeof(u64));
-   if (!prog_addrs) {
-   pr_debug("%s: failed to allocate memory for prog_addrs, 
aborting\n", __func__);
-   goto out;
-   }
-   prog_lens = calloc(sub_prog_cnt, sizeof(u32));
-   if (!prog_lens) {
-   pr_debug("%s: failed to allocate memory for prog_lens, 
aborting\n", __func__);
-   goto out;
-   }
-   prog_tags = calloc(sub_prog_cnt, BPF_TAG_SIZE);
-   if (!prog_tags) {
-   

[PATCH v9 perf,bpf 05/15] perf: change prototype of perf_event__synthesize_bpf_events()

2019-03-11 Thread Song Liu
This patch changes the arguments of perf_event__synthesize_bpf_events()
to include perf_session* instead of perf_tool*. perf_session will be used
in the next patch.

Signed-off-by: Song Liu 
---
 tools/perf/builtin-record.c | 2 +-
 tools/perf/builtin-top.c| 2 +-
 tools/perf/util/bpf-event.c | 8 +---
 tools/perf/util/bpf-event.h | 4 ++--
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 458dcd0cc0e7..2d34039c4246 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1093,7 +1093,7 @@ static int record__synthesize(struct record *rec, bool 
tail)
return err;
}
 
-   err = perf_event__synthesize_bpf_events(tool, process_synthesized_event,
+   err = perf_event__synthesize_bpf_events(session, 
process_synthesized_event,
machine, opts);
if (err < 0)
pr_warning("Couldn't synthesize bpf events.\n");
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 231a90daa958..09c0721c97df 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1212,7 +1212,7 @@ static int __cmd_top(struct perf_top *top)
 
init_process_thread(top);
 
-   ret = perf_event__synthesize_bpf_events(>tool, perf_event__process,
+   ret = perf_event__synthesize_bpf_events(top->session, 
perf_event__process,
>session->machines.host,
>record_opts);
if (ret < 0)
diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c
index e9d9854be506..eedd0f7dfe0c 100644
--- a/tools/perf/util/bpf-event.c
+++ b/tools/perf/util/bpf-event.c
@@ -10,6 +10,7 @@
 #include "debug.h"
 #include "symbol.h"
 #include "machine.h"
+#include "session.h"
 
 #define ptr_to_u64(ptr)((__u64)(unsigned long)(ptr))
 
@@ -42,7 +43,7 @@ int machine__process_bpf_event(struct machine *machine 
__maybe_unused,
  *   -1 for failures;
  *   -2 for lack of kernel support.
  */
-static int perf_event__synthesize_one_bpf_prog(struct perf_tool *tool,
+static int perf_event__synthesize_one_bpf_prog(struct perf_session *session,
   perf_event__handler_t process,
   struct machine *machine,
   int fd,
@@ -52,6 +53,7 @@ static int perf_event__synthesize_one_bpf_prog(struct 
perf_tool *tool,
struct ksymbol_event *ksymbol_event = >ksymbol_event;
struct bpf_event *bpf_event = >bpf_event;
struct bpf_prog_info_linear *info_linear;
+   struct perf_tool *tool = session->tool;
struct bpf_prog_info *info;
struct btf *btf = NULL;
bool has_btf = false;
@@ -175,7 +177,7 @@ static int perf_event__synthesize_one_bpf_prog(struct 
perf_tool *tool,
return err ? -1 : 0;
 }
 
-int perf_event__synthesize_bpf_events(struct perf_tool *tool,
+int perf_event__synthesize_bpf_events(struct perf_session *session,
  perf_event__handler_t process,
  struct machine *machine,
  struct record_opts *opts)
@@ -209,7 +211,7 @@ int perf_event__synthesize_bpf_events(struct perf_tool 
*tool,
continue;
}
 
-   err = perf_event__synthesize_one_bpf_prog(tool, process,
+   err = perf_event__synthesize_one_bpf_prog(session, process,
  machine, fd,
  event, opts);
close(fd);
diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h
index 7890067e1a37..6698683612a7 100644
--- a/tools/perf/util/bpf-event.h
+++ b/tools/perf/util/bpf-event.h
@@ -15,7 +15,7 @@ struct record_opts;
 int machine__process_bpf_event(struct machine *machine, union perf_event 
*event,
   struct perf_sample *sample);
 
-int perf_event__synthesize_bpf_events(struct perf_tool *tool,
+int perf_event__synthesize_bpf_events(struct perf_session *session,
  perf_event__handler_t process,
  struct machine *machine,
  struct record_opts *opts);
@@ -27,7 +27,7 @@ static inline int machine__process_bpf_event(struct machine 
*machine __maybe_unu
return 0;
 }
 
-static inline int perf_event__synthesize_bpf_events(struct perf_tool *tool 
__maybe_unused,
+static inline int perf_event__synthesize_bpf_events(struct perf_session 
*session __maybe_unused,
perf_event__handler_t 
process __maybe_unused,
struct machine *machine 
__maybe_unused,
   

[PATCH v7 08/12] perf record: implement compression for AIO trace streaming

2019-03-11 Thread Alexey Budankov


Compression is implemented using the functions from zstd.c. As the memory
to operate on the compression uses mmap->aio.data[] buffers. If Zstd
streaming compression API fails for some reason the data to be compressed
are just copied into the memory buffers using plain memcpy().

Compressed trace frame consists of an array of PERF_RECORD_COMPRESSED
records. Each element of the array is not longer that PERF_SAMPLE_MAX_SIZE
and consists of perf_event_header followed by the compressed chunk
that is decompressed on the loading stage.

perf_mmap__aio_push() is replaced by perf_mmap__push() which is now used
in the both serial and AIO streaming cases. perf_mmap__push() is extended 
with positive return values to signify absence of data ready for processing.

Signed-off-by: Alexey Budankov 
---
 tools/perf/builtin-record.c | 110 
 tools/perf/util/mmap.c  |  76 +
 tools/perf/util/mmap.h  |  12 
 3 files changed, 87 insertions(+), 111 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d13c0dd87592..47e0abe22192 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -130,6 +130,8 @@ static int record__write(struct record *rec, struct 
perf_mmap *map __maybe_unuse
return 0;
 }
 
+static int record__aio_enabled(struct record *rec);
+static int record__comp_enabled(struct record *rec);
 static size_t zstd_compress(struct perf_session *session, void *dst, size_t 
dst_size,
void *src, size_t src_size);
 
@@ -183,9 +185,9 @@ static int record__aio_complete(struct perf_mmap *md, 
struct aiocb *cblock)
if (rem_size == 0) {
cblock->aio_fildes = -1;
/*
-* md->refcount is incremented in perf_mmap__push() for
-* every enqueued aio write request so decrement it because
-* the request is now complete.
+* md->refcount is incremented in record__aio_pushfn() for
+* every aio write request started in record__aio_push() so
+* decrement it because the request is now complete.
 */
perf_mmap__put(md);
rc = 1;
@@ -240,18 +242,89 @@ static int record__aio_sync(struct perf_mmap *md, bool 
sync_all)
} while (1);
 }
 
-static int record__aio_pushfn(void *to, struct aiocb *cblock, void *bf, size_t 
size, off_t off)
+struct record_aio {
+   struct record   *rec;
+   void*data;
+   size_t  size;
+};
+
+static int record__aio_pushfn(struct perf_mmap *map, void *to, void *buf, 
size_t size)
 {
-   struct record *rec = to;
-   int ret, trace_fd = rec->session->data->file.fd;
+   struct record_aio *aio = to;
 
-   rec->samples++;
+   /*
+* map->base data pointed by buf is copied into free map->aio.data[] 
buffer
+* to release space in the kernel buffer as fast as possible, calling
+* perf_mmap__consume() from perf_mmap__push() function.
+*
+* That lets the kernel to proceed with storing more profiling data into
+* the kernel buffer earlier than other per-cpu kernel buffers are 
handled.
+*
+* Coping can be done in two steps in case the chunk of profiling data
+* crosses the upper bound of the kernel buffer. In this case we first 
move
+* part of data from map->start till the upper bound and then the 
reminder
+* from the beginning of the kernel buffer till the end of the data 
chunk.
+*/
+
+   if (record__comp_enabled(aio->rec)) {
+   size = zstd_compress(aio->rec->session, aio->data + aio->size,
+perf_mmap__mmap_len(map) - aio->size,
+buf, size);
+   } else {
+   memcpy(aio->data + aio->size, buf, size);
+   }
+
+   if (!aio->size) {
+   /*
+* Increment map->refcount to guard map->aio.data[] buffer
+* from premature deallocation because map object can be
+* released earlier than aio write request started on
+* map->aio.data[] buffer is complete.
+*
+* perf_mmap__put() is done at record__aio_complete()
+* after started aio request completion or at record__aio_push()
+* if the request failed to start.
+*/
+   perf_mmap__get(map);
+   }
+
+   aio->size += size;
+
+   return size;
+}
+
+static int record__aio_push(struct record *rec, struct perf_mmap *map, off_t 
*off)
+{
+   int ret, idx;
+   int trace_fd = rec->session->data->file.fd;
+   struct record_aio aio = { .rec = rec, .size = 0 };
 
-   ret = record__aio_write(cblock, trace_fd, bf, size, off);
+   /*
+* Call record__aio_sync() to wait till map->aio.data[] buffer
+* 

[PATCH v7 07/12] perf record: implement compression for serial trace streaming

2019-03-11 Thread Alexey Budankov


Compression is implemented using the functions from zstd.c. As the memory
to operate on the compression uses mmap->data buffer. If Zstd streaming
compression API fails for some reason the data to be compressed are just
copied into the memory buffers using plain memcpy().

Compressed trace frame consists of an array of PERF_RECORD_COMPRESSED
records. Each element of the array is not longer that PERF_SAMPLE_MAX_SIZE
and consists of perf_event_header followed by the compressed chunk
that is decompressed on the loading stage.

Signed-off-by: Alexey Budankov 
---
 tools/perf/builtin-record.c | 52 +++--
 tools/perf/util/session.h   |  2 ++
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index c4ce5a9c9e3f..d13c0dd87592 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -130,6 +130,9 @@ static int record__write(struct record *rec, struct 
perf_mmap *map __maybe_unuse
return 0;
 }
 
+static size_t zstd_compress(struct perf_session *session, void *dst, size_t 
dst_size,
+   void *src, size_t src_size);
+
 #ifdef HAVE_AIO_SUPPORT
 static int record__aio_write(struct aiocb *cblock, int trace_fd,
void *buf, size_t size, off_t off)
@@ -387,6 +390,12 @@ static int record__pushfn(struct perf_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);
+   bf = map->data;
+   }
+
rec->samples++;
return record__write(rec, map, bf, size);
 }
@@ -773,6 +782,37 @@ static void record__adjust_affinity(struct record *rec, 
struct perf_mmap *map)
}
 }
 
+static size_t process_comp_header(void *record, size_t increment)
+{
+   struct compressed_event *event = record;
+   size_t size = sizeof(struct compressed_event);
+
+   if (increment) {
+   event->header.size += increment;
+   return increment;
+   } else {
+   event->header.type = PERF_RECORD_COMPRESSED;
+   event->header.size = size;
+   return size;
+   }
+}
+
+static size_t zstd_compress(struct perf_session *session, void *dst, size_t 
dst_size,
+   void *src, size_t src_size)
+{
+   size_t compressed;
+   size_t max_record_size = PERF_SAMPLE_MAX_SIZE - sizeof(struct 
compressed_event);
+
+   compressed = zstd_compress_stream_to_records(&(session->zstd_data),
+   dst, dst_size, src, src_size, max_record_size,
+   process_comp_header);
+
+   session->bytes_transferred += src_size;
+   session->bytes_compressed  += compressed;
+
+   return compressed;
+}
+
 static int record__mmap_read_evlist(struct record *rec, struct perf_evlist 
*evlist,
bool overwrite, bool sync)
 {
@@ -1202,6 +1242,14 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
fd = perf_data__fd(data);
rec->session = session;
 
+   if (zstd_init(&(session->zstd_data), rec->opts.comp_level) < 0) {
+   pr_err("Compression initialization failed.\n");
+   return -1;
+   }
+
+   session->header.env.comp_type  = PERF_COMP_ZSTD;
+   session->header.env.comp_level = rec->opts.comp_level;
+
record__init_features(rec);
 
if (rec->opts.use_clockid && rec->opts.clockid_res_ns)
@@ -1535,6 +1583,7 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
}
 
 out_delete_session:
+   zstd_fini(&(session->zstd_data));
perf_session__delete(session);
return status;
 }
@@ -2252,8 +2301,7 @@ int cmd_record(int argc, const char **argv)
 
if (rec->opts.nr_cblocks > nr_cblocks_max)
rec->opts.nr_cblocks = nr_cblocks_max;
-   if (verbose > 0)
-   pr_info("nr_cblocks: %d\n", rec->opts.nr_cblocks);
+   pr_debug("nr_cblocks: %d\n", rec->opts.nr_cblocks);
 
pr_debug("affinity: %s\n", affinity_tags[rec->opts.affinity]);
pr_debug("mmap flush: %d\n", rec->opts.mmap_flush);
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 0e14884f28b2..6c984c895924 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -8,6 +8,7 @@
 #include "machine.h"
 #include "data.h"
 #include "ordered-events.h"
+#include "util/compress.h"
 #include 
 #include 
 #include 
@@ -37,6 +38,7 @@ struct perf_session {
struct perf_tool*tool;
u64 bytes_transferred;
u64 bytes_compressed;
+   struct zstd_datazstd_data;
 };
 
 struct perf_tool;
-- 
2.20.1



Re: [PATCH v3 0/1] mm: introduce put_user_page*(), placeholder versions

2019-03-11 Thread Christopher Lameter
On Mon, 11 Mar 2019, Dave Chinner wrote:

> > Direct IO on a mmapped file backed page doesnt make any sense.
>
> People have used it for many, many years as zero-copy data movement
> pattern. i.e. mmap the destination file, use direct IO to DMA direct
> into the destination file page cache pages, fdatasync() to force
> writeback of the destination file.

Well we could make that more safe through a special API that designates a
range of pages in a file in the same way as for RDMA. This is inherently
not reliable as we found out.

> Now we have copy_file_range() to optimise this sort of data
> movement, the need for games with mmap+direct IO largely goes away.
> However, we still can't just remove that functionality as it will
> break lots of random userspace stuff...

It is already broken and unreliable. Are there really "lots" of these
things around? Can we test this by adding a warning in the kernel and see
where it actually crops up?


[PATCH v7 06/12] perf util: introduce Zstd based streaming compression API

2019-03-11 Thread Alexey Budankov


Implemented functions are based on Zstd streaming compression API.
The functions are used in runtime to compress data that come from
mmaped kernel buffer. zstd_init(), zstd_fini() are used for 
initialization and finalization to allocate and deallocate internal
zstd objects. zstd_compress_stream_to_records() is used to convert 
parts of mmaped kernel buffer into an array of PERF_RECORD_COMPRESSED 
records.

Signed-off-by: Alexey Budankov 
---
 tools/perf/util/Build  |  2 +
 tools/perf/util/compress.h | 18 
 tools/perf/util/zstd.c | 95 ++
 3 files changed, 115 insertions(+)
 create mode 100644 tools/perf/util/zstd.c

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8dd3102301ea..920ee8bebd83 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -145,6 +145,8 @@ perf-y += scripting-engines/
 
 perf-$(CONFIG_ZLIB) += zlib.o
 perf-$(CONFIG_LZMA) += lzma.o
+perf-y += zstd.o
+
 perf-y += demangle-java.o
 perf-y += demangle-rust.o
 
diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h
index 892e92e7e7fc..e0987616db94 100644
--- a/tools/perf/util/compress.h
+++ b/tools/perf/util/compress.h
@@ -2,6 +2,11 @@
 #ifndef PERF_COMPRESS_H
 #define PERF_COMPRESS_H
 
+#include 
+#ifdef HAVE_ZSTD_SUPPORT
+#include 
+#endif
+
 #ifdef HAVE_ZLIB_SUPPORT
 int gzip_decompress_to_file(const char *input, int output_fd);
 bool gzip_is_compressed(const char *input);
@@ -12,4 +17,17 @@ int lzma_decompress_to_file(const char *input, int 
output_fd);
 bool lzma_is_compressed(const char *input);
 #endif
 
+struct zstd_data {
+#ifdef HAVE_ZSTD_SUPPORT
+   ZSTD_CStream*cstream;
+#endif
+};
+
+int zstd_init(struct zstd_data *data, int level);
+int zstd_fini(struct zstd_data *data);
+
+size_t zstd_compress_stream_to_records(struct zstd_data *data,
+   void *dst, size_t dst_size, void *src, size_t src_size, size_t 
max_record_size,
+   size_t process_header(void *record, size_t increment));
+
 #endif /* PERF_COMPRESS_H */
diff --git a/tools/perf/util/zstd.c b/tools/perf/util/zstd.c
new file mode 100644
index ..e5d44d0f6b5d
--- /dev/null
+++ b/tools/perf/util/zstd.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+
+#include "util/compress.h"
+#include "util/debug.h"
+
+#ifdef HAVE_ZSTD_SUPPORT
+
+int zstd_init(struct zstd_data *data, int level)
+{
+   size_t ret;
+
+   data->cstream = ZSTD_createCStream();
+   if (data->cstream == NULL) {
+   pr_err("Couldn't create compression stream.\n");
+   return -1;
+   }
+
+   ret = ZSTD_initCStream(data->cstream, level);
+   if (ZSTD_isError(ret)) {
+   pr_err("Failed to initialize compression stream: %s\n", 
ZSTD_getErrorName(ret));
+   return -1;
+   }
+
+   return 0;
+}
+
+int zstd_fini(struct zstd_data *data)
+{
+   if (data->cstream) {
+   ZSTD_freeCStream(data->cstream);
+   data->cstream = NULL;
+   }
+
+   return 0;
+}
+
+size_t zstd_compress_stream_to_records(struct zstd_data *data,
+   void *dst, size_t dst_size, void *src, size_t src_size, size_t 
max_record_size,
+   size_t process_header(void *record, size_t increment))
+{
+   size_t ret, size, compressed = 0;
+   ZSTD_inBuffer input = { src, src_size, 0 };
+   ZSTD_outBuffer output;
+   void *record;
+
+   while (input.pos < input.size) {
+   record = dst;
+   size = process_header(record, 0);
+   compressed += size;
+   dst += size;
+   dst_size -= size;
+   output = (ZSTD_outBuffer){ dst, (dst_size > max_record_size) ?
+   max_record_size : dst_size, 0 };
+   ret = ZSTD_compressStream(data->cstream, , );
+   ZSTD_flushStream(data->cstream, );
+   if (ZSTD_isError(ret)) {
+   pr_err("failed to compress %ld bytes: %s\n",
+   (long)src_size, ZSTD_getErrorName(ret));
+   memcpy(dst, src, src_size);
+   return src_size;
+   }
+   size = output.pos;
+   size = process_header(record, size);
+   compressed += size;
+   dst += size;
+   dst_size -= size;
+   }
+
+   return compressed;
+}
+
+#else /* !HAVE_ZSTD_SUPPORT */
+
+int zstd_init(struct zstd_data *data __maybe_unused, int level __maybe_unused)
+{
+   return 0;
+}
+
+int zstd_fini(struct zstd_data *data __maybe_unused)
+{
+   return 0;
+}
+
+size_t zstd_compress_stream_to_records(struct zstd_data *data __maybe_unused,
+   void *dst __maybe_unused, size_t dst_size __maybe_unused,
+   void *src __maybe_unused, size_t src_size __maybe_unused,
+   size_t max_record_size __maybe_unused,
+   size_t process_header(void *record, size_t 

[PATCH v7 05/12] perf mmap: implement dedicated memory buffer for data compression

2019-03-11 Thread Alexey Budankov


Implemented mmap data buffer that is used as the memory to operate
on when compressing data in case of serial trace streaming.

Signed-off-by: Alexey Budankov 
---
 tools/perf/builtin-record.c |  6 +-
 tools/perf/util/evlist.c|  8 +---
 tools/perf/util/evlist.h|  2 +-
 tools/perf/util/mmap.c  | 30 --
 tools/perf/util/mmap.h  |  4 +++-
 5 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index b823241d6641..c4ce5a9c9e3f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -584,7 +584,7 @@ static int record__mmap_evlist(struct record *rec,
 opts->auxtrace_mmap_pages,
 opts->auxtrace_snapshot_mode,
 opts->nr_cblocks, opts->affinity,
-opts->mmap_flush) < 0) {
+opts->mmap_flush, opts->comp_level) < 0) {
if (errno == EPERM) {
pr_err("Permission error mapping pages.\n"
   "Consider increasing "
@@ -2258,6 +2258,10 @@ int cmd_record(int argc, const char **argv)
pr_debug("affinity: %s\n", affinity_tags[rec->opts.affinity]);
pr_debug("mmap flush: %d\n", rec->opts.mmap_flush);
 
+   if (rec->opts.comp_level > 22)
+   rec->opts.comp_level = 0;
+   pr_debug("comp level: %d\n", rec->opts.comp_level);
+
err = __cmd_record(, argc, argv);
 out:
perf_evlist__delete(rec->evlist);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 8858d829983b..4d8a25a12430 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1037,7 +1037,8 @@ int perf_evlist__parse_mmap_pages(const struct option 
*opt, const char *str,
  */
 int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
 unsigned int auxtrace_pages,
-bool auxtrace_overwrite, int nr_cblocks, int affinity, 
int flush)
+bool auxtrace_overwrite, int nr_cblocks, int affinity, 
int flush,
+int comp_level)
 {
struct perf_evsel *evsel;
const struct cpu_map *cpus = evlist->cpus;
@@ -1047,7 +1048,8 @@ int perf_evlist__mmap_ex(struct perf_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 };
+   struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = 
affinity, .flush = flush,
+ .comp_level = comp_level };
 
if (!evlist->mmap)
evlist->mmap = perf_evlist__alloc_mmap(evlist, false);
@@ -1079,7 +1081,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, 
unsigned int pages,
 
 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages)
 {
-   return perf_evlist__mmap_ex(evlist, pages, 0, false, 0, 
PERF_AFFINITY_SYS, 1);
+   return perf_evlist__mmap_ex(evlist, pages, 0, false, 0, 
PERF_AFFINITY_SYS, 1, 0);
 }
 
 int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index edf18811e39f..77c11dac4a63 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -166,7 +166,7 @@ unsigned long perf_event_mlock_kb_in_pages(void);
 int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
 unsigned int auxtrace_pages,
 bool auxtrace_overwrite, int nr_cblocks,
-int affinity, int flush);
+int affinity, int flush, int comp_level);
 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages);
 void perf_evlist__munmap(struct perf_evlist *evlist);
 
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index ef3d79b2c90b..d85e73fc82e2 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -157,6 +157,10 @@ void __weak auxtrace_mmap_params__set_idx(struct 
auxtrace_mmap_params *mp __mayb
 }
 
 #ifdef HAVE_AIO_SUPPORT
+static int perf_mmap__aio_enabled(struct perf_mmap *map)
+{
+   return map->aio.nr_cblocks > 0;
+}
 
 #ifdef HAVE_LIBNUMA_SUPPORT
 static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
@@ -198,7 +202,7 @@ static int perf_mmap__aio_bind(struct perf_mmap *map, int 
idx, int cpu, int affi
 
return 0;
 }
-#else
+#else /* !HAVE_LIBNUMA_SUPPORT */
 static int perf_mmap__aio_alloc(struct perf_mmap *map, int idx)
 {
map->aio.data[idx] = malloc(perf_mmap__mmap_len(map));
@@ -359,7 +363,12 @@ int perf_mmap__aio_push(struct perf_mmap *md, void *to, 
int idx,
 
return rc;
 }
-#else
+#else /* !HAVE_AIO_SUPPORT */
+static int 

[PATCH v7 04/12] perf record: implement COMPRESSED event record and its attributes

2019-03-11 Thread Alexey Budankov


Implemented PERF_RECORD_COMPRESSED event, related data types, header
feature and functions to write, read and print feature attributes
from the trace header section.

comp_mmap_len preserves the size of mmaped kernel buffer that was used
during collection. comp_mmap_len size is used on loading stage as the
size of decomp buffer for decompression of COMPRESSED events content.

Signed-off-by: Alexey Budankov 
---
 .../Documentation/perf.data-file-format.txt   | 24 
 tools/perf/builtin-record.c   |  8 +++
 tools/perf/perf.h |  1 +
 tools/perf/util/env.h | 10 
 tools/perf/util/event.c   |  1 +
 tools/perf/util/event.h   |  7 +++
 tools/perf/util/header.c  | 55 ++-
 tools/perf/util/header.h  |  1 +
 8 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf.data-file-format.txt 
b/tools/perf/Documentation/perf.data-file-format.txt
index 593ef49b273c..418fa0bce52e 100644
--- a/tools/perf/Documentation/perf.data-file-format.txt
+++ b/tools/perf/Documentation/perf.data-file-format.txt
@@ -272,6 +272,19 @@ struct {
 
 Two uint64_t for the time of first sample and the time of last sample.
 
+HEADER_COMPRESSED = 24,
+
+struct {
+   u32 version;
+   u32 type;
+   u32 level;
+   u32 ratio;
+   u32 mmap_len;
+};
+
+Indicates that trace contains records of PERF_RECORD_COMPRESSED type
+that have perf_events records in compressed form.
+
other bits are reserved and should ignored for now
HEADER_FEAT_BITS= 256,
 
@@ -437,6 +450,17 @@ struct auxtrace_error_event {
 Describes a header feature. These are records used in pipe-mode that
 contain information that otherwise would be in perf.data file's header.
 
+   PERF_RECORD_COMPRESSED  = 81,
+
+struct compressed_event {
+   struct perf_event_headerheader;
+   chardata[];
+};
+
+The header is followed by compressed data frame that can be decompressed
+into array of perf trace records. The size of the entire compressed event
+record including the header is limited by the max value of header.size.
+
 Event types
 
 Define the event attributes with their IDs.
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bc0a895e7e80..b823241d6641 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -369,6 +369,11 @@ static int record__mmap_flush_parse(const struct option 
*opt,
return 0;
 }
 
+static int record__comp_enabled(struct record *rec)
+{
+   return rec->opts.comp_level > 0;
+}
+
 static int process_synthesized_event(struct perf_tool *tool,
 union perf_event *event,
 struct perf_sample *sample __maybe_unused,
@@ -885,6 +890,8 @@ static void record__init_features(struct record *rec)
perf_header__clear_feat(>header, HEADER_CLOCKID);
 
perf_header__clear_feat(>header, HEADER_DIR_FORMAT);
+   if (!record__comp_enabled(rec))
+   perf_header__clear_feat(>header, HEADER_COMPRESSED);
 
perf_header__clear_feat(>header, HEADER_STAT);
 }
@@ -1224,6 +1231,7 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
err = -1;
goto out_child;
}
+   session->header.env.comp_mmap_len = session->evlist->mmap_len;
 
err = bpf__apply_obj_config();
if (err) {
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 7886cc9771cf..2c6caad45b10 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -86,6 +86,7 @@ struct record_opts {
int  nr_cblocks;
int  affinity;
int  mmap_flush;
+   unsigned int comp_level;
 };
 
 enum perf_affinity {
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index fb39e9af128f..7990d63ab764 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -65,6 +65,16 @@ struct perf_env {
unsigned long long   memory_bsize;
u64 clockid_res_ns;
u32 comp_ratio;
+   u32 comp_ver;
+   u32 comp_type;
+   u32 comp_level;
+   u32 comp_mmap_len;
+};
+
+enum perf_compress_type {
+   PERF_COMP_NONE = 0,
+   PERF_COMP_ZSTD,
+   PERF_COMP_MAX
 };
 
 extern struct perf_env perf_env;
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ba7be74fad6e..d1ad6c419724 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -68,6 +68,7 @@ static const char *perf_event__names[] = {
[PERF_RECORD_EVENT_UPDATE]  = "EVENT_UPDATE",
[PERF_RECORD_TIME_CONV] = "TIME_CONV",

[PATCH v7 03/12] perf session: define bytes_transferred and bytes_compressed metrics

2019-03-11 Thread Alexey Budankov


Define bytes_transferred and bytes_compressed metrics to calculate ratio
in the end of the data collection:

compression ratio = bytes_transferred / bytes_compressed 

bytes_transferred accumulates the amount of bytes that was extracted from 
the mmaped kernel buffers for compression. bytes_compressed accumulates 
the amount of bytes that was received after applying compression.

Signed-off-by: Alexey Budankov 
---
 tools/perf/builtin-record.c | 14 +-
 tools/perf/util/env.h   |  1 +
 tools/perf/util/session.h   |  2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 736a0f008959..bc0a895e7e80 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1502,6 +1502,7 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
char samples[128];
const char *postfix = rec->timestamp_filename ?
"." : "";
+   float ratio = 0;
 
if (rec->samples && !rec->opts.full_auxtrace)
scnprintf(samples, sizeof(samples),
@@ -1509,9 +1510,20 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
else
samples[0] = '\0';
 
-   fprintf(stderr, "[ perf record: Captured and wrote %.3f MB 
%s%s%s ]\n",
+   if (rec->session->bytes_transferred && 
rec->session->bytes_compressed) {
+   ratio = 
(float)rec->session->bytes_transferred/(float)rec->session->bytes_compressed;
+   session->header.env.comp_ratio = ratio + 0.5;
+   }
+
+   fprintf(stderr, "[ perf record: Captured and wrote %.3f MB 
%s%s%s",
perf_data__size(data) / 1024.0 / 1024.0,
data->path, postfix, samples);
+   if (ratio) {
+   fprintf(stderr, ", compressed (original %.3f MB, ratio 
is %.3f)",
+   rec->session->bytes_transferred / 
1024.0 / 1024.0,
+   ratio);
+   }
+   fprintf(stderr, " ]\n");
}
 
 out_delete_session:
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index d01b8355f4ca..fb39e9af128f 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -64,6 +64,7 @@ struct perf_env {
struct memory_node  *memory_nodes;
unsigned long long   memory_bsize;
u64 clockid_res_ns;
+   u32 comp_ratio;
 };
 
 extern struct perf_env perf_env;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index d96eccd7d27f..0e14884f28b2 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -35,6 +35,8 @@ struct perf_session {
struct ordered_events   ordered_events;
struct perf_data*data;
struct perf_tool*tool;
+   u64 bytes_transferred;
+   u64 bytes_compressed;
 };
 
 struct perf_tool;
-- 
2.20.1



[PATCH v7 02/12] perf record: implement -f,--mmap-flush= option

2019-03-11 Thread Alexey Budankov


Implemented -f,--mmap-flush option that specifies minimal size of data
chunk that is extracted from mmaped kernel buffer to store into a trace.
The default option value is 1 byte what means every time trace writing
thread finds some new data in the mmaped buffer the data is extracted,
possibly compressed and written to a trace.

  $ tools/perf/perf record -f 1024 -e cycles -- matrix.gcc
  $ tools/perf/perf record --aio -f 1K -e cycles -- matrix.gcc

The option is independent from -z setting, doesn't vary with compression
level and can serve two purposes.

The first purpose is to increase the compression ratio of a trace data.
Larger data chunks are compressed more effectively so the implemented 
option allows specifying data chunk size to compress. Also at some cases 
executing more write syscalls with smaller data size can take longer 
than executing less write syscalls with bigger data size due to syscall 
overhead so extracting bigger data chunks specified by the option value 
could additionally decrease runtime overhead.

The second purpose is to avoid self monitoring live-lock issue in system
wide (-a) profiling mode. Profiling in system wide mode with compression
(-a -z) can additionally induce data into the kernel buffers along with 
the data from monitored processes. If performance data rate and volume 
from the monitored processes is high then trace streaming and compression 
activity in the tool is also high. High tool process activity can lead 
to subtle live-lock effect when compression of single new byte from some
of mmaped kernel buffer leads to generation of the next single byte at 
some mmaped buffer. So perf tool process ends up in endless self monitoring.

Implemented sync param is the mean to force data move independently from
the specified flush threshold value. Despite the provided flush value the
tool needs capability to unconditionally drain memory buffers, at least
in the end of the collection.

Signed-off-by: Alexey Budankov 
---
 tools/perf/Documentation/perf-record.txt | 13 +
 tools/perf/builtin-record.c  | 65 +---
 tools/perf/perf.h|  1 +
 tools/perf/util/evlist.c |  6 +--
 tools/perf/util/evlist.h |  3 +-
 tools/perf/util/mmap.c   |  4 +-
 tools/perf/util/mmap.h   |  3 +-
 7 files changed, 83 insertions(+), 12 deletions(-)

diff --git a/tools/perf/Documentation/perf-record.txt 
b/tools/perf/Documentation/perf-record.txt
index 8f0c2be34848..d1e6c1fd7387 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -459,6 +459,19 @@ Set affinity mask of trace reading thread according to the 
policy defined by 'mo
   node - thread affinity mask is set to NUMA node cpu mask of the processed 
mmap buffer
   cpu  - thread affinity mask is set to cpu of the processed mmap buffer
 
+-f::
+--mmap-flush=n::
+Specify minimal number of bytes that is extracted from mmap data pages and 
stored
+into a trace. The number specification is possible using B/K/M/G suffixes. 
Maximal allowed
+value is a quarter of the size of mmaped data pages. The default option value 
is 1 byte
+what means that every time trace writing thread finds some new data in the 
mmaped buffer
+the data is extracted, possibly compressed (-z) and written to a trace. Larger 
data chunks
+are compressed more effectively in comparison to smaller chunks so extraction 
of larger
+chunks from the mmap data pages is preferable from perspective of trace size 
reduction.
+Also at some cases executing less trace write syscalls with bigger data size 
can take
+shorter than executing more trace write syscalls with smaller data size thus 
lowering
+runtime profiling overhead.
+
 --all-kernel::
 Configure all used events to run in kernel space.
 
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index a468d882e74f..736a0f008959 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -334,6 +334,41 @@ static int record__aio_enabled(struct record *rec)
return rec->opts.nr_cblocks > 0;
 }
 
+#define MMAP_FLUSH_DEFAULT 1
+static int record__mmap_flush_parse(const struct option *opt,
+   const char *str,
+   int unset)
+{
+   int flush_max;
+   struct record_opts *opts = (struct record_opts *)opt->value;
+   static struct parse_tag tags[] = {
+   { .tag  = 'B', .mult = 1   },
+   { .tag  = 'K', .mult = 1 << 10 },
+   { .tag  = 'M', .mult = 1 << 20 },
+   { .tag  = 'G', .mult = 1 << 30 },
+   { .tag  = 0 },
+   };
+
+   if (unset)
+   return 0;
+
+   if (str) {
+   opts->mmap_flush = parse_tag_value(str, tags);
+   if (opts->mmap_flush == (int)-1)
+   opts->mmap_flush = strtol(str, 

Re: [PATCH v9 1/9] bitops: Introduce the for_each_set_clump8 macro

2019-03-11 Thread Masahiro Yamada
On Sun, Mar 3, 2019 at 4:48 PM William Breathitt Gray
 wrote:
>
> This macro iterates for each 8-bit group of bits (clump) with set bits,
> within a bitmap memory region. For each iteration, "start" is set to the
> bit offset of the found clump, while the respective clump value is
> stored to the location pointed by "clump". Additionally, the
> bitmap_get_value8 and bitmap_set_value8 functions are introduced to
> respectively get and set an 8-bit value in a bitmap memory region.
>
> Suggested-by: Andy Shevchenko 
> Suggested-by: Rasmus Villemoes 
> Cc: Arnd Bergmann 
> Cc: Andrew Morton 
> Reviewed-by: Andy Shevchenko 
> Reviewed-by: Linus Walleij 
> Signed-off-by: William Breathitt Gray 
> ---
>  include/asm-generic/bitops/find.h | 14 ++
>  include/linux/bitops.h|  5 ++
>  lib/find_bit.c| 81 +++
>  3 files changed, 100 insertions(+)
>
> diff --git a/include/asm-generic/bitops/find.h 
> b/include/asm-generic/bitops/find.h
> index 8a1ee10014de..9a76adff59c6 100644
> --- a/include/asm-generic/bitops/find.h
> +++ b/include/asm-generic/bitops/find.h
> @@ -80,4 +80,18 @@ extern unsigned long find_first_zero_bit(const unsigned 
> long *addr,
>
>  #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
>
> +unsigned long bitmap_get_value8(const unsigned long *const bitmap,
> +   const unsigned int size,
> +   const unsigned int start);
> +
> +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size,
> +  const unsigned long value, const unsigned int start);
> +
> +unsigned int find_next_clump8(unsigned long *const clump,
> + const unsigned long *const addr,
> + unsigned int offset, const unsigned int size);
> +
> +#define find_first_clump8(clump, bits, size) \
> +   find_next_clump8((clump), (bits), 0, (size))
> +
>  #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index 705f7c442691..61c10f20079e 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -40,6 +40,11 @@ extern unsigned long __sw_hweight64(__u64 w);
>  (bit) < (size);\
>  (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
>
> +#define for_each_set_clump8(start, clump, bits, size) \
> +   for ((start) = find_first_clump8(&(clump), (bits), (size)); \
> +(start) < (size); \
> +(start) = find_next_clump8(&(clump), (bits), (start) + 8, 
> (size)))
> +
>  static inline int get_bitmask_order(unsigned int count)
>  {
> int order;
> diff --git a/lib/find_bit.c b/lib/find_bit.c
> index ee3df93ba69a..c2af1f013ea2 100644
> --- a/lib/find_bit.c
> +++ b/lib/find_bit.c
> @@ -218,3 +218,84 @@ EXPORT_SYMBOL(find_next_bit_le);
>  #endif
>
>  #endif /* __BIG_ENDIAN */
> +
> +/**
> + * bitmap_get_value8 - get an 8-bit value within a memory region
> + * @bitmap: address to the bitmap memory region
> + * @size: bitmap size in number of bits
> + * @start: bit offset of the 8-bit value
> + *
> + * Returns the 8-bit value located at the @start bit offset within the 
> @bitmap
> + * memory region.
> + */
> +unsigned long bitmap_get_value8(const unsigned long *const bitmap,
> +   const unsigned int size,
> +   const unsigned int start)


The comment says this function returns '8-bit value'.

The return type should be 'u8' instead of 'unsigned long', then.

Same for other helpers.



> +{
> +   const size_t index = BIT_WORD(start);
> +   const unsigned int offset = start % BITS_PER_LONG;
> +   const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ?
> +  BITS_PER_LONG - offset : 8;
> +   const unsigned long low = bitmap[index] >> offset;
> +   const unsigned long high = (low_width < 8 && start + 8 <= size) ?
> +  bitmap[index + 1] << low_width : 0;


I do not know if we have a usecase
where the 'start' is not multiple of 8, though.



-- 
Best Regards
Masahiro Yamada


[PATCH v7 01/12] feature: implement libzstd check, LIBZSTD_DIR and NO_LIBZSTD defines

2019-03-11 Thread Alexey Budankov


Implement libzstd feature check, NO_LIBZSTD and LIBZSTD_DIR defines
to override Zstd library sources or disable the feature from the
command line:

  $ make -C tools/perf LIBZSTD_DIR=/path/to/zstd/sources/ clean all
  $ make -C tools/perf NO_LIBZSTD=1 clean all

Auto detection feature status is reported just before compilation starts.
If your system has some version of the zstd library preinstalled then
the build system finds and uses it during the build.

If you still prefer to compile with some other version of zstd library
you have capability to refer the compilation to that version using 
LIBZSTD_DIR define.

Signed-off-by: Alexey Budankov 
---
 tools/build/Makefile.feature   |  6 --
 tools/build/feature/Makefile   |  6 +-
 tools/build/feature/test-all.c |  5 +
 tools/build/feature/test-libzstd.c | 12 
 tools/perf/Makefile.config | 20 
 tools/perf/Makefile.perf   |  3 +++
 tools/perf/builtin-version.c   |  2 ++
 7 files changed, 51 insertions(+), 3 deletions(-)
 create mode 100644 tools/build/feature/test-libzstd.c

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 61e46d54a67c..adf791cbd726 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -66,7 +66,8 @@ FEATURE_TESTS_BASIC :=  \
 sched_getcpu   \
 sdt\
 setns  \
-libaio
+libaio \
+libzstd
 
 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
 # of all feature tests
@@ -118,7 +119,8 @@ FEATURE_DISPLAY ?=  \
  lzma   \
  get_cpuid  \
  bpf   \
- libaio
+ libaio\
+ libzstd
 
 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
 # If in the future we need per-feature checks/flags for features not
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 7ceb4441b627..4b8244ee65ce 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -62,7 +62,8 @@ FILES=  \
  test-clang.bin\
  test-llvm.bin \
  test-llvm-version.bin \
- test-libaio.bin
+ test-libaio.bin   \
+ test-libzstd.bin
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
@@ -301,6 +302,9 @@ $(OUTPUT)test-clang.bin:
 $(OUTPUT)test-libaio.bin:
$(BUILD) -lrt
 
+$(OUTPUT)test-libzstd.bin:
+   $(BUILD) -lzstd
+
 ###
 
 clean:
diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c
index e903b86b742f..b0dda7db2a17 100644
--- a/tools/build/feature/test-all.c
+++ b/tools/build/feature/test-all.c
@@ -178,6 +178,10 @@
 # include "test-reallocarray.c"
 #undef main
 
+#define main main_test_zstd
+# include "test-libzstd.c"
+#undef main
+
 int main(int argc, char *argv[])
 {
main_test_libpython();
@@ -219,6 +223,7 @@ int main(int argc, char *argv[])
main_test_setns();
main_test_libaio();
main_test_reallocarray();
+   main_test_libzstd();
 
return 0;
 }
diff --git a/tools/build/feature/test-libzstd.c 
b/tools/build/feature/test-libzstd.c
new file mode 100644
index ..55268c01b84d
--- /dev/null
+++ b/tools/build/feature/test-libzstd.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+
+int main(void)
+{
+   ZSTD_CStream*cstream;
+
+   cstream = ZSTD_createCStream();
+   ZSTD_freeCStream(cstream);
+
+   return 0;
+}
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 0f11d5891301..4949bdb16a66 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -152,6 +152,13 @@ endif
 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) 
-lbabeltrace-ctf
 
+ifdef LIBZSTD_DIR
+  LIBZSTD_CFLAGS  := -I$(LIBZSTD_DIR)/lib
+  LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
+endif
+FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
+FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
+
 FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include 
-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
 # include ARCH specific config
 -include $(src-perf)/arch/$(SRCARCH)/Makefile
@@ -782,6 +789,19 @@ ifndef NO_LZMA
   endif
 endif
 
+ifndef NO_LIBZSTD
+  ifeq ($(feature-libzstd), 1)
+CFLAGS += -DHAVE_ZSTD_SUPPORT
+CFLAGS += $(LIBZSTD_CFLAGS)
+LDFLAGS += $(LIBZSTD_LDFLAGS)
+EXTLIBS += -lzstd
+$(call detected,CONFIG_ZSTD)
+  else
+msg := $(warning No libzstd found, disables trace compression, please 
install libzstd-dev[el] and/or set LIBZSTD_DIR);
+NO_LIBZSTD := 1
+  

Re: [PATCH v3 0/3] gcov: add Clang support

2019-03-11 Thread Tri Vo
On Tue, Mar 5, 2019 at 6:29 AM Peter Oberparleiter
 wrote:
>
> On 23.01.2019 00:37, Tri Vo wrote:
> > This patch series adds Clang supoprt for gcov.
> >
> > Patch 1 refactors existing code in preparation for Clang support.
> > Patch 2 implements necessary LLVM runtime hooks and gcov kernel interfaces.
> > Patch 3 updates documentation.
>
> Thanks for the updates! I've provided suggestions for some minor
> improvements in my other review e-mails.
>
> With those changes applied, the patch set is in my opinion ready for
> inclusion into the mainline kernel. My suggestion would be to re-post
> the resulting version while putting Andrew Morton on CC as gcov changes
> are typically integrated via his tree.
>
> Also I've successfully re-tested this patch set version on s390 using
> GCC 7.3.0 to ensure that the existing GCC support is still working.
> Unfortunately I wasn't able to test the Clang version due to some
> compile problems on s390 (unrelated to this patch set).
>
> If you haven't done so, I would like to suggest to run the following
> tests with the Clang gcov-kernel version that should catch problems in
> some corner cases:
>
> 1. Unload a module, then use llvm-cov on the associated coverage file.
>
>Expectation: correct llvm-cov output including coverage of module
>exit code.
>
> 2. Unload a module, modify its source, re-compile it and load it again,
>then use llvm-cov on the associated coverage file.
>
>Expectation: kernel message "discarding saved data", correct llvm-cov
>output with no coverage of module exit code.
>
> 3. Unload a module, then reset all coverage data by writing to
>/sys/kernel/debug/gcov/reset.
>
>Expectation: all coverage files associated with the module are
>removed from debugfs.

Thanks for the suggested test cases! The current patchset doesn't seem
to handle module loading/unloading correctly. I'll fix that in a
follow-up.


[PATCH v7 00/12] perf: enable compression of record mode trace to save storage space

2019-03-11 Thread Alexey Budankov


The patch set implements runtime trace compression (-z option) in 
record mode and trace auto decompression in report and inject modes. 
Streaming Zstd API [1] is used for compression and decompression of
data that come from kernel mmaped data buffers.

Usage of implemented -z,--compression_level=n option provides ~3-5x 
avg. trace file size reduction on variety of tested workloads what 
saves storage space on larger server systems where trace file size 
can easily reach several tens or even hundreds of GiBs, especially 
when profiling with dwarf-based stacks and tracing of context switches.

Implemented -f,--mmap-flush option can be used to specify minimal size 
of data chunk that is extracted from mmaped kernel buffer to store
into a trace. The option is independent from -z setting and doesn't 
vary with compression level. The default option value is 1 byte what 
means every time trace writing thread finds some new data in the 
mmaped buffer the data is extracted, possibly compressed and written 
to a trace. The option serves two purposes the first one is to increase 
the compression ratio of trace data and the second one is to avoid 
live-lock self tool process monitoring in system wide (-a) profiling
mode. Profiling in system wide mode with compression (-a -z) can 
additionally induce data into the kernel buffers along with the data 
from monitored processes. If performance data rate and volume from 
the monitored processes is high then trace streaming and compression 
activity in the tool is also high. It can lead to subtle live-lock 
effect of endless activity when compression of single new byte from 
some of mmaped kernel buffer induces the next single byte at some 
mmaped buffer. So perf tool thread never stops on polling event file 
descriptors. Varying data chunk size to be extracted from mmap buffers 
allows avoiding live-locking self monitoring in system wide mode and
makes mmap buffers polling loop tuneable.

  $ tools/perf/perf record -z 1 -e cycles -- matrix.gcc
  $ tools/perf/perf record --aio=1 -z 1 -e cycles -- matrix.gcc
  $ tools/perf/perf record -z 1 -f 1024 -e cycles -- matrix.gcc
  $ tools/perf/perf record --aio -z 1 -f 1K -e cycles -- matrix.gcc

Runtime compression overhead has been measured for serial and AIO 
trace writing modes when profiling matrix multiplication workload 
with the following results:

-
| SERIAL  | AIO-1   |
|-|-|
|-z | OVH(x) | ratio(x) size(MiB) | OVH(x) | ratio(x) size(MiB) |
|---|||||
| 0 | 1,00   | 1,000179,424   | 1,00   | 1,000187,527   |
| 1 | 1,04   | 8,427181,148   | 1,01   | 8,474188,562   |
| 2 | 1,07   | 8,055186,953   | 1,03   | 7,912191,773   |
| 3 | 1,04   | 8,283181,908   | 1,03   | 8,220191,078   |
| 5 | 1,09   | 8,101187,705   | 1,05   | 7,780190,065   |
| 8 | 1,05   | 9,217179,191   | 1,12   | 6,111193,024   |
-

OVH = (Execution time with -z N) / (Execution time with -z 0)

ratio - compression ratio
size  - number of bytes that was compressed

size ~= trace file x ratio

See complete description of measurement conditions with details below.

Introduced compression functionality can be disabled or configured from 
the command line using NO_LIBZSTD and LIBZSTD_DIR defines:

  $ make -C tools/perf NO_LIBZSTD=1 clean all
  $ make -C tools/perf LIBZSTD_DIR=/path/to/zstd/sources/ clean all

If your system has some version of the zstd package preinstalled then 
the build system finds and uses it during the build. Auto detection 
feature status is reported just before compilation starts, as usual.
If you still prefer to compile with some other version of zstd you have 
capability to refer the compilation to that version using LIBZSTD_DIR 
define.

See 'perf test' results below for enabled and disabled (NO_LIBZSTD=1)
feature configurations.

---
Alexey Budankov (12):
  feature: implement libzstd check, LIBZSTD_DIR and NO_LIBZSTD defines
  perf record: implement -f,--mmap-flush= option
  perf session: define bytes_transferred and bytes_compressed metrics
  perf record: implement COMPRESSED event record and its attributes
  perf mmap: implement dedicated memory buffer for data compression
  perf util: introduce Zstd based streaming compression API
  perf record: implement compression for serial trace streaming
  perf record: implement compression for AIO trace streaming
  perf record: implement -z,--compression_level=n option
  perf report: implement record trace decompression
  perf inject: enable COMPRESSED records decompression
  perf tests: implement Zstd comp/decomp integration test

 tools/build/Makefile.feature  |   6 +-
 tools/build/feature/Makefile  |   6 +-
 

[PATCH] PM / OPP: Update performance state when freq == old_freq

2019-03-11 Thread Viresh Kumar
At boot up, CPUfreq core performs a sanity check to see if the system is
running at a frequency defined in the frequency table of the CPU. If so,
we try to find a valid frequency (lowest frequency greater than the
currently programmed frequency) from the table and set it. When the call
reaches dev_pm_opp_set_rate(), it calls _find_freq_ceil(opp_table,
_freq) to find the previously configured OPP and this call also
updates the old_freq. This eventually sets the old_freq == freq (new
target requested by cpufreq core) and we skip updating the performance
state in this case.

Fix this by also updating the performance state when the old_freq ==
freq.

Fixes: ca1b5d77b1c6 ("OPP: Configure all required OPPs")
Cc: v5.0  # v5.0
Reported-by: Niklas Cassel 
Signed-off-by: Viresh Kumar 
---
 drivers/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index d7f97167cac3..0420f7e8ad5b 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -760,7 +760,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long 
target_freq)
old_freq, freq);
 
/* Scaling up? Configure required OPPs before frequency */
-   if (freq > old_freq) {
+   if (freq >= old_freq) {
ret = _set_required_opps(dev, opp_table, opp);
if (ret)
goto put_opp;
-- 
2.21.0.rc0.269.g1a574e7a288b



Re: [PATCH] net: fjes: fix potential NULL pointer dereferences

2019-03-11 Thread Kangjie Lu



> On Mar 11, 2019, at 6:19 PM, David Miller  wrote:
> 
> From: Kangjie Lu 
> Date: Mon, 11 Mar 2019 02:10:21 -0500
> 
>>  adapter->control_wq = alloc_workqueue(DRV_NAME "/control",
>>WQ_MEM_RECLAIM, 0);
>> +if (!adapter->control_wq) {
>> +err = -ENOMEM;
>> +goto err_free_netdev;
>> +}
> 
> This error path leaks adapter->txrx_wq.

The following code also has an error-handling case: goto err_free_netdev.
Shouldn’t the resource release be in err_free_netdev?

> 



Re: [PATCH v3 0/1] mm: introduce put_user_page*(), placeholder versions

2019-03-11 Thread Christopher Lameter
On Fri, 8 Mar 2019, Jerome Glisse wrote:

> >
> > It would good if that understanding would be enforced somehow given the 
> > problems
> > that we see.
>
> This has been discuss extensively already. GUP usage is now widespread in
> multiple drivers, removing that would regress userspace ie break existing
> application. We all know what the rules for that is.

The applications that work are using anonymous memory and memory
filesystems. I have never seen use cases with a real filesystem and would
have objected if someone tried something crazy like that.

Because someone was able to get away with weird ways of abusing the system
it not an argument that we should continue to allow such things. In fact
we have repeatedly ensured that the kernel works reliably by improving the
kernel so that a proper failure is occurring.


> > > In fact, the GUP documentation even recommends that pattern.
> >
> > Isnt that pattern safe for anonymous memory and memory filesystems like
> > hugetlbfs etc? Which is the common use case.
>
> Still an issue in respect to swapout ie if anon/shmem page was map
> read only in preparation for swapout and we do not report the page
> as dirty what endup in swap might lack what was written last through
> GUP.

Well swapout cannot occur if the page is pinned and those pages are also
often mlocked.

> >
> > Yes you now have the filesystem as well as the GUP pinner claiming
> > authority over the contents of a single memory segment. Maybe better not
> > allow that?
>
> This goes back to regressing existing driver with existing users.

There is no regression if that behavior never really worked.

> > Two filesystem trying to sync one memory segment both believing to have
> > exclusive access and we want to sort this out. Why? Dont allow this.
>
> This is allowed, it always was, forbidding that case now would regress
> existing application and it would also means that we are modifying the
> API we expose to userspace. So again this is not something we can block
> without regressing existing user.

We have always stopped the user from doing obviously stupid and risky
things. It would be logical to do it here as well.



RE: [PATCHv4 10/28] PCI: mobiveil: fix the INTx process error

2019-03-11 Thread Z.q. Hou
Hi Bjorn,

Thanks a lot for your comments!

> -Original Message-
> From: Bjorn Helgaas [mailto:helg...@kernel.org]
> Sent: 2019年3月11日 22:08
> To: Z.q. Hou 
> Cc: linux-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; linux-kernel@vger.kernel.org;
> robh...@kernel.org; mark.rutl...@arm.com; l.subrahma...@mobiveil.co.in;
> shawn...@kernel.org; Leo Li ;
> lorenzo.pieral...@arm.com; catalin.mari...@arm.com;
> will.dea...@arm.com; M.h. Lian ; Xiaowei Bao
> ; Mingkai Hu 
> Subject: Re: [PATCHv4 10/28] PCI: mobiveil: fix the INTx process error
> 
> On Mon, Mar 11, 2019 at 09:31:16AM +, Z.q. Hou wrote:
> > From: Hou Zhiqiang 
> >
> > In the loop block, there is not code change the loop key, this patch
> > updated the loop key by re-read the INTx status register.
> >
> > This patch also change to clear the handled INTx status.
> >
> > Note: Need MV to test this fix.
> >
> > Fixes: 9af6bcb11e12 ("PCI: mobiveil: Add Mobiveil PCIe Host Bridge IP
> > driver")
> 
> The "Fixes:" line should be all on one line, without a newline in the middle,
> even if it exceeds 80 columns.  That's just to make it easier for programs to
> parse the logs.

Will fix in v5.

Thanks,
Zhiqiang


RE: [PATCHv4 24/28] PCI: mobiveil: add PCIe Gen4 RC driver for NXP Layerscape SoCs

2019-03-11 Thread Z.q. Hou
Hi Bjorn,

Thanks a lot for your comments!

> -Original Message-
> From: Bjorn Helgaas [mailto:helg...@kernel.org]
> Sent: 2019年3月11日 22:02
> To: Z.q. Hou 
> Cc: linux-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; linux-kernel@vger.kernel.org;
> robh...@kernel.org; mark.rutl...@arm.com; l.subrahma...@mobiveil.co.in;
> shawn...@kernel.org; Leo Li ;
> lorenzo.pieral...@arm.com; catalin.mari...@arm.com;
> will.dea...@arm.com; Mingkai Hu ; M.h. Lian
> ; Xiaowei Bao 
> Subject: Re: [PATCHv4 24/28] PCI: mobiveil: add PCIe Gen4 RC driver for NXP
> Layerscape SoCs
> 
> On Mon, Mar 11, 2019 at 09:33:16AM +, Z.q. Hou wrote:
> > From: Hou Zhiqiang 
> >
> > This PCIe controller is based on the Mobiveil GPEX IP, which is
> > compatible with the PCI Express™ Base Specification, Revision 4.0.
> >
> > Signed-off-by: Hou Zhiqiang 
> > Reviewed-by: Minghuan Lian 
> > ---
> > V4:
> >  - no change
> >
> >  drivers/pci/controller/mobiveil/Kconfig   |  10 +
> >  drivers/pci/controller/mobiveil/Makefile  |   1 +
> >  .../controller/mobiveil/pci-layerscape-gen4.c | 254 ++
> >  .../pci/controller/mobiveil/pcie-mobiveil.h   |  16 +-
> >  4 files changed, 279 insertions(+), 2 deletions(-)  create mode
> > 100644 drivers/pci/controller/mobiveil/pci-layerscape-gen4.c
> >
> > diff --git a/drivers/pci/controller/mobiveil/Kconfig
> > b/drivers/pci/controller/mobiveil/Kconfig
> > index 64343c07bfed..3ddb7d6163a9 100644
> > --- a/drivers/pci/controller/mobiveil/Kconfig
> > +++ b/drivers/pci/controller/mobiveil/Kconfig
> > @@ -21,4 +21,14 @@ config PCIE_MOBIVEIL_PLAT
> >   Soft IP. It has up to 8 outbound and inbound windows
> >   for address translation and it is a PCIe Gen4 IP.
> >
> > +config PCI_LAYERSCAPE_GEN4
> > +   bool "Freescale Layerscpe PCIe Gen4 controller"
> 
> "Layerscape"

Will fix in v5.

> 
> > +   depends on PCI
> > +   depends on OF && (ARM64 || ARCH_LAYERSCAPE)
> > +   depends on PCI_MSI_IRQ_DOMAIN
> > +   select PCIE_MOBIVEIL_HOST
> > +   help
> > + Say Y here if you want PCIe Gen4 controller support on
> > + Layerscape SoCs. The PCIe controller can work in RC or
> > + EP mode according to RCW[HOST_AGT_PEX] setting.
> >  endmenu
> > diff --git a/drivers/pci/controller/mobiveil/Makefile
> > b/drivers/pci/controller/mobiveil/Makefile
> > index 9fb6d1c6504d..ff66774ccac4 100644
> > --- a/drivers/pci/controller/mobiveil/Makefile
> > +++ b/drivers/pci/controller/mobiveil/Makefile
> > @@ -2,3 +2,4 @@
> >  obj-$(CONFIG_PCIE_MOBIVEIL) += pcie-mobiveil.o
> >  obj-$(CONFIG_PCIE_MOBIVEIL_HOST) += pcie-mobiveil-host.o
> >  obj-$(CONFIG_PCIE_MOBIVEIL_PLAT) += pcie-mobiveil-plat.o
> > +obj-$(CONFIG_PCI_LAYERSCAPE_GEN4) += pci-layerscape-gen4.o
> > diff --git a/drivers/pci/controller/mobiveil/pci-layerscape-gen4.c
> > b/drivers/pci/controller/mobiveil/pci-layerscape-gen4.c
> > new file mode 100644
> > index ..174cbcac4059
> > --- /dev/null
> > +++ b/drivers/pci/controller/mobiveil/pci-layerscape-gen4.c
> > @@ -0,0 +1,254 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * PCIe host controller driver for NXP Layerscape SoCs
> 
> It would be nice to make "NXP Layerscape SoCs" a little more specific so we
> can tell how it's different from the existing pci-layerscape.c that says
> "Freescale Layerscape SoCs".  I assume this driver only works with gen4
> parts.

Yes, it is only for NXP SoCs with Mobiveil PCIe Gen4 controller, and will add 
specific in v5.

> 
> > + * Copyright 2018 NXP
> 
> s/2018/2019/
> 

Will fix in v5.

> > + *
> > + * Author: Zhiqiang Hou  */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "pcie-mobiveil.h"
> > +
> > +/* LUT and PF control registers */
> > +#define PCIE_LUT_OFF   (0x8)
> > +#define PCIE_PF_OFF(0xc)
> > +#define PCIE_PF_INT_STAT   (0x18)
> > +#define PF_INT_STAT_PABRST (31)
> 
> You mix constants that are
> 
>   - the bit position (like this), and
>   - the actual bit mask, like PAB_INTP_RESET
> 
> Pick one and use a single style.  My personal preference is a plain hex bit
> mask, e.g.,
> 
>   #define PF_INT_STAT_PABRST0x8000
>   #define PAB_INTP_RESET0x0002
> 
> But some people like BIT() or the style you used for PAB_INTP_RESET:
> 
>   #define PAB_INTP_RESETBIT(1)
>   #define PAB_INTP_RESET(0x1 << 1)
> 
> I definitely don't like the simple bit position like this:
> 
>   #define PF_INT_STAT_PABRST31
> 
> because that means you have to repeat things like
> "1 << PF_INT_STAT_PABRST" everywhere you use it.
> 

Will unify them in v5.

> > +#define PCIE_PF_DBG(0x7fc)
> > +#define PF_DBG_LTSSM_MASK  (0x3f)
> > +#define PF_DBG_WE  (31)
> > +#define PF_DBG_PABR  

Re: [RFC 04/15] slub: Enable Slab Movable Objects (SMO)

2019-03-11 Thread Christopher Lameter
On Mon, 11 Mar 2019, Roman Gushchin wrote:

> > +static inline void *alloc_scratch(struct kmem_cache *s)
> > +{
> > +   unsigned int size = oo_objects(s->max);
> > +
> > +   return kmalloc(size * sizeof(void *) +
> > +  BITS_TO_LONGS(size) * sizeof(unsigned long),
> > +  GFP_KERNEL);
>
> I wonder how big this allocation can be?
> Given that the reason for migration is probably highly fragmented memory,
> we probably don't want to have a high-order allocation here. So maybe
> kvmalloc()?

The smallest object size is 8 bytes which is one word which would be
places in an order 0 page. So it comes out to about a page again.

Larger allocation orders are possible if the slab pages itself can have
larger orders of course. If you set the min_order to the huge page order
then we can have similar sized orders for the allocation of the scratch
space. However, that is not a problem since the allocations for the slab
pages itself are also already of that same order.



[PATCH v2] net: brcm80211: fix missing checks for kmemdup

2019-03-11 Thread Kangjie Lu
In case kmemdup fails, the fix sets conn_info->req_ie_len to zero
to avoid buffer overflows.

Signed-off-by: Kangjie Lu 
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c 
b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index e92f6351bd22..5d9a3c35fef5 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -5464,6 +5464,8 @@ static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info 
*cfg,
conn_info->req_ie =
kmemdup(cfg->extra_buf, conn_info->req_ie_len,
GFP_KERNEL);
+   if (!conn_info->req_ie)
+   conn_info->req_ie_len = 0;
} else {
conn_info->req_ie_len = 0;
conn_info->req_ie = NULL;
@@ -5480,6 +5482,8 @@ static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info 
*cfg,
conn_info->resp_ie =
kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
GFP_KERNEL);
+   if (!conn_info->resp_ie)
+   conn_info->req_ie_len = 0;
} else {
conn_info->resp_ie_len = 0;
conn_info->resp_ie = NULL;
-- 
2.17.1



[GIT PULL] chrome-platform updates for v5.1

2019-03-11 Thread Benson Leung
Hi Linus,

The following changes since commit 49a57857aeea06ca831043acbb0fa5e0f50602fd:

  Linux 5.0-rc3 (2019-01-21 13:14:44 +1300)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git 
tags/tag-chrome-platform-for-v5.1

for you to fetch changes up to 2794449576a6024e203eca5cc2c1a3ae33102b8e:

  platform/chrome: fix wilco-ec dependencies (2019-03-05 11:35:46 +0100)


chrome platform changes for v5.1

1. SPDX identifier cleanup for platform/chrome
2. Cleanup series between mfd and chrome/platform, moving
   cros-ec attributes from mfd/cros_ec_dev to sub-drivers in platform/chrome.
3. Wilco EC driver
4. Maintainership change to new group repository.


Arnd Bergmann (1):
  platform/chrome: fix wilco-ec dependencies

Enric Balletbo i Serra (20):
  mfd / platform: cros_ec: Use devm_mfd_add_devices
  mfd / platform: cros_ec: Move lightbar attributes to its own driver
  mfd / platform: cros_ec: Move vbc attributes to its own driver
  mfd / platform: cros_ec: Move debugfs attributes to its own driver
  mfd / platform: cros_ec: Move device sysfs attributes to its own driver
  mfd / platform: cros_ec_vbc: Instantiate only if the EC has a VBC NVRAM
  platform/chrome: cros_ec_lightbar: Instantiate only if the EC has a 
lightbar
  platform/chrome: cromeos_pstore: switch to SPDX identifier
  platform/chrome: cros_ec_debugfs: switch to SPDX identifier
  platform/chrome: cros_ec_lightbar: switch to SPDX identifier
  platform/chrome: cros_ec_sysfs: switch to SPDX identifier
  platform/chrome: cros_ec_vbc: switch to SPDX identifier
  platform/chrome: cros_ec_i2c: switch to SPDX identifier
  platform/chrome: cros_ec_lpc: switch to SPDX identifier
  platform/chrome: cros_ec_proto: switch to SPDX identifier
  platform/chrome: cros_ec_spi: switch to SPDX identifier
  platform/chrome: cros_kbd_led_backlight: switch to SPDX identifier
  platform/chrome: cros_ec_lightbar: remove pr_fmt() define
  platform/chrome: cros_ec_sysfs: remove pr_fmt() define
  MAINTAINERS: chrome-platform: change the git tree to a chrome-platform 
group git tree

Nick Crews (4):
  platform/chrome: cros_ec: Remove cros_ec dependency in lpc_mec
  platform/chrome: Add new driver for Wilco EC

Thank you,
Benson
-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
ble...@google.com
Chromium OS Project
ble...@chromium.org


signature.asc
Description: PGP signature


Re: [PATCH v9 9/9] gpio: uniphier: Utilize for_each_set_clump8 macro

2019-03-11 Thread Masahiro Yamada
On Sun, Mar 3, 2019 at 4:51 PM William Breathitt Gray
 wrote:
>
> Replace verbose implementation in set_multiple callback with
> for_each_set_clump8 macro to simplify code and improve clarity. An
> improvement in this case is that banks that are not masked will now be
> skipped.
>
> Cc: Masahiro Yamada 
> Signed-off-by: William Breathitt Gray 
> ---
>  drivers/gpio/gpio-uniphier.c | 16 ++--
>  1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c
> index 0f662b297a95..df640cb29b9c 100644
> --- a/drivers/gpio/gpio-uniphier.c
> +++ b/drivers/gpio/gpio-uniphier.c
> @@ -15,9 +15,6 @@
>  #include 
>  #include 
>
> -#define UNIPHIER_GPIO_BANK_MASK\
> -   GENMASK((UNIPHIER_GPIO_LINES_PER_BANK) - 1, 0)
> -
>  #define UNIPHIER_GPIO_IRQ_MAX_NUM  24
>
>  #define UNIPHIER_GPIO_PORT_DATA0x0 /* data */
> @@ -147,15 +144,14 @@ static void uniphier_gpio_set(struct gpio_chip *chip,
>  static void uniphier_gpio_set_multiple(struct gpio_chip *chip,
>unsigned long *mask, unsigned long 
> *bits)
>  {
> -   unsigned int bank, shift, bank_mask, bank_bits;
> -   int i;
> +   unsigned int i;
> +   unsigned long bank_mask;
> +   unsigned int bank;
> +   unsigned int bank_bits;
>
> -   for (i = 0; i < chip->ngpio; i += UNIPHIER_GPIO_LINES_PER_BANK) {
> +   for_each_set_clump8(i, bank_mask, mask, chip->ngpio) {
> bank = i / UNIPHIER_GPIO_LINES_PER_BANK;
> -   shift = i % BITS_PER_LONG;
> -   bank_mask = (mask[BIT_WORD(i)] >> shift) &
> -   UNIPHIER_GPIO_BANK_MASK;
> -   bank_bits = bits[BIT_WORD(i)] >> shift;
> +   bank_bits = bitmap_get_value8(bits, chip->ngpio, i);
>
> uniphier_gpio_bank_write(chip, bank, UNIPHIER_GPIO_PORT_DATA,
>  bank_mask, bank_bits);


Please do not do this.

Nothing in this driver says the GPIO width is 8-bit.

You are hard-coding '8-bit'.







> --
> 2.21.0
>


-- 
Best Regards
Masahiro Yamada


Re: [RFC 02/15] slub: Add isolate() and migrate() methods

2019-03-11 Thread Christopher Lameter
On Mon, 11 Mar 2019, Roman Gushchin wrote:

> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -4325,6 +4325,34 @@ int __kmem_cache_create(struct kmem_cache *s, 
> > slab_flags_t flags)
> > return err;
> >  }
> >
> > +void kmem_cache_setup_mobility(struct kmem_cache *s,
> > +  kmem_cache_isolate_func isolate,
> > +  kmem_cache_migrate_func migrate)
> > +{
>
> I wonder if it's better to adapt kmem_cache_create() to take two additional
> argument? I suspect mobility is not a dynamic option, so it can be
> set on kmem_cache creation.

One other idea that prior versions of this patchset used was to change
kmem_cache_create() so that the ctor parameter becomes an ops vector.

However, in order to reduce the size of the patchset I dropped that. It
could be easily moved back to the way it was before.

> > +   /*
> > +* Sadly serialization requirements currently mean that we have
> > +* to disable fast cmpxchg based processing.
> > +*/
>
> Can you, please, elaborate a bit more here?

cmpxchg based processing does not lock the struct page. SMO requires to
ensure that all changes on a slab page can be stopped. The page->lock will
accomplish that. I think we could avoid dealing with actually locking the
page with some more work.


[BUG] perf/core: report a task hung issue in __perf_event_ctx_lock_double()

2019-03-11 Thread liwei (GF)
Hi peter,
The syzkaller reported a task hung issue, and it was on a qemu x86_64 machine 
with kernel 4.19.27.
I analysed and found that, the gctx got in __perf_event_ctx_lock_double and ctx 
are just equal.It is
caused by race between two concurrent sys_perf_event_open() calls where both 
try and move the same
pre-existing software group into a hardware context. In commit 321027c1fe77f8 
("perf/core: Fix
concurrent sys_perf_event_open() vs. 'move_group' race"), i found you have 
tried to solve this
problem before. I am afraid a only check can not avoid the race, should we use 
a lock here?

[ 1295.914975] INFO: task syz-executor.2:23733 blocked for more than 140 
seconds.
[ 1295.921446]   Not tainted 4.19.27 #2
[ 1295.922994] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[ 1295.925517] syz-executor.2  D27904 23733   2683 0x1004
[ 1295.927009] Call Trace:
[ 1295.928737]  ? __schedule+0x755/0x1a80
[ 1295.931396]  ? __sched_text_start+0x8/0x8
[ 1295.936207]  ? do_raw_spin_unlock+0x54/0x220
[ 1295.937339]  schedule+0x7c/0x1a0
[ 1295.938256]  schedule_preempt_disabled+0x11/0x20
[ 1295.939493]  __mutex_lock+0x83b/0x1240
[ 1295.940548]  ? perf_event_ctx_lock_nested+0x1fd/0x440
[ 1295.952024]  ? mutex_lock_io_nested+0x10d0/0x10d0
[ 1295.953217]  ? perf_event_ctx_lock_nested+0x1fd/0x440
[ 1295.954488]  ? ftrace_ops_list_func+0x1c1/0x380
[ 1295.955611]  ? perf_trace_buf_alloc+0x200/0x200
[ 1295.956759]  ? ftrace_call+0x5/0x34
[ 1295.969703]  ? perf_event_ctx_lock_nested+0x1fd/0x440
[ 1295.971336]  ? perf_event_ctx_lock_nested+0x1fd/0x440
[ 1295.972778]  perf_event_ctx_lock_nested+0x1fd/0x440
[ 1295.974994]  ? perf_event_read_event+0x2a0/0x2a0
[ 1295.976346]  ? perf_event_release_kernel+0x94d/0xc70
[ 1295.977643]  ? perf_event_release_kernel+0x955/0xc70
[ 1295.978941]  perf_event_release_kernel+0x108/0xc70
[ 1295.980134]  ? ftrace_call+0x5/0x34
[ 1295.981086]  ? locks_remove_file+0x2b5/0x3e0
[ 1295.992160]  ? put_event+0x40/0x40
[ 1295.993186]  ? perf_event_release_kernel+0xc70/0xc70
[ 1295.994496]  perf_release+0x33/0x40
[ 1295.995494]  __fput+0x27f/0x7f0
[ 1295.996445]  task_work_run+0x136/0x1b0
[ 1295.997536]  exit_to_usermode_loop+0x1a7/0x1d0
[ 1295.998727]  do_syscall_64+0x461/0x580
[ 1295.999800]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 1296.001076] RIP: 0033:0x412387
[ 1296.001962] Code: Bad RIP value.
[ 1296.002768] RSP: 002b:7ffde0b42b40 EFLAGS: 0293 ORIG_RAX: 
0003
[ 1296.009717] RAX:  RBX: 0004 RCX: 00412387
[ 1296.011609] RDX:  RSI: 00741c60 RDI: 0004
[ 1296.013436] RBP: 7ffde0b42bac R08: 000ffd52 R09: 000ffd52
[ 1296.035032] R10: 7ffde0b42a80 R11: 0293 R12: 0001
[ 1296.039400] R13: 0001 R14:  R15: 0002
[ 1296.052258] INFO: task syz-executor.2:23734 blocked for more than 140 
seconds.
[ 1296.067589]   Not tainted 4.19.27 #2
[ 1296.068545] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[ 1296.070573] syz-executor.2  D28432 23734   2683 0x1004
[ 1296.072028] Call Trace:
[ 1296.072700]  ? __schedule+0x755/0x1a80
[ 1296.073747]  ? __sched_text_start+0x8/0x8
[ 1296.081141]  ? do_raw_spin_unlock+0x54/0x220
[ 1296.082784]  schedule+0x7c/0x1a0
[ 1296.084135]  schedule_preempt_disabled+0x11/0x20
[ 1296.085506]  __mutex_lock+0x83b/0x1240
[ 1296.086609]  ? __do_sys_perf_event_open+0xff5/0x2090
[ 1296.088051]  ? mutex_lock_io_nested+0x10d0/0x10d0
[ 1296.097169]  ? __do_sys_perf_event_open+0xff5/0x2090
[ 1296.098224]  ? ftrace_ops_list_func+0x1c1/0x380
[ 1296.099256]  ? perf_trace_buf_alloc+0x200/0x200
[ 1296.110608]  ? ftrace_call+0x5/0x34
[ 1296.111662]  ? __do_sys_perf_event_open+0xff5/0x2090
[ 1296.113844]  ? __do_sys_perf_event_open+0xff5/0x2090
[ 1296.115350]  __do_sys_perf_event_open+0xff5/0x2090
[ 1296.116812]  ? perf_event_set_output+0x480/0x480
[ 1296.118742]  ? rcu_read_lock_sched_held+0x107/0x120
[ 1296.120136]  ? syscall_trace_enter+0x285/0xb80
[ 1296.122451]  ? do_syscall_64+0x3e3/0x580
[ 1296.124165]  do_syscall_64+0xc8/0x580
[ 1296.125766]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 1296.128241] RIP: 0033:0x462eb9
[ 1296.130131] Code: Bad RIP value.
[ 1296.131104] RSP: 002b:7f6024d51c58 EFLAGS: 0246 ORIG_RAX: 
012a
[ 1296.132763] RAX: ffda RBX: 0073bf00 RCX: 00462eb9
[ 1296.148678] RDX:  RSI:  RDI: 2040
[ 1296.151821] RBP: 0005 R08:  R09: 
[ 1296.156380] R10: 0008 R11: 0246 R12: 7f6024d526bc
[ 1296.160438] R13: 004c2df7 R14: 006ffc10 R15: 
[ 1296.165410] 
[ 1296.165410] Showing all locks held in the system:
[ 1296.168411] 1 lock held by khungtaskd/54:
[ 1296.170580]  #0: d6c02832 (rcu_read_lock){}, at: 
debug_show_all_locks+0x57/0x310
[ 

RE: [PATCHv4 00/28] PCI: refactor Mobiveil driver and add PCIe Gen4 driver for NXP Layerscape SoCs

2019-03-11 Thread Z.q. Hou
Hi Bjorn,

Thanks a lot for your comments!

> -Original Message-
> From: Bjorn Helgaas [mailto:helg...@kernel.org]
> Sent: 2019年3月11日 21:33
> To: Z.q. Hou 
> Cc: linux-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; linux-kernel@vger.kernel.org;
> robh...@kernel.org; mark.rutl...@arm.com; l.subrahma...@mobiveil.co.in;
> shawn...@kernel.org; Leo Li ;
> lorenzo.pieral...@arm.com; catalin.mari...@arm.com;
> will.dea...@arm.com; M.h. Lian ; Xiaowei Bao
> ; Mingkai Hu 
> Subject: Re: [PATCHv4 00/28] PCI: refactor Mobiveil driver and add PCIe Gen4
> driver for NXP Layerscape SoCs
> 
> Hi,
> 
> On Mon, Mar 11, 2019 at 09:29:54AM +, Z.q. Hou wrote:
> > From: Hou Zhiqiang 
> >
> > This patch set is aim to refactor the Mobiveil driver and add PCIe
> > support for NXP Layerscape series SoCs integrated Mobiveil's PCIe Gen4
> > controller.
> >
> > Hou Zhiqiang (28):
> >   PCI: mobiveil: uniform the register accessors
> 
> "uniform" is not a verb.  Maybe "Unify register accessors"?
> 
> >   PCI: mobiveil: format the code without function change
> >   PCI: mobiveil: correct the returned error number
> >   PCI: mobiveil: remove flag MSI_FLAG_MULTI_PCI_MSI
> >   PCI: mobiveil: correct PCI base address in MEM/IO outbound windows
> >   PCI: mobiveil: replace the resource list iteration function
> >   PCI: mobiveil: use WIN_NUM_0 explicitly for CFG outbound window
> >   PCI: mobiveil: use the 1st inbound window for MEM inbound
> transactions
> >   PCI: mobiveil: correct inbound/outbound window setup routines
> >   PCI: mobiveil: fix the INTx process error
> >   PCI: mobiveil: only fix up the Class Code field
> >   PCI: mobiveil: move out the link up waiting from mobiveil_host_init
> 
> Add parens for function names, e.g., "mobiveil_host_init()".  This occurs
> several more times, including both subject lines and changelogs.
> 
> >   PCI: mobiveil: move irq chained handler setup out of DT parse
> 
> Capitalize acronyms in English text (subject lines, changelogs, comments), 
> e.g.,
> s/irq/IRQ/
> 
> >   PCI: mobiveil: initialize Primary/Secondary/Subordinate bus number
> >   dt-bindings: pci: mobiveil: change gpio_slave and apb_csr to optional
> >   PCI: mobiveil: refactor Mobiveil PCIe Host Bridge IP driver
> 
> This should give a hint about the purpose of refactoring.  Sounds like it's to
> make it easier to support both host and endpoint mode?
> 
> >   PCI: mobiveil: fix the checking of valid device
> >   PCI: mobiveil: add link up condition check
> >   PCI: mobiveil: continue to initialize the host upon no PCIe link
> >   PCI: mobiveil: disabled IB and OB windows set by bootloader
> >   PCI: mobiveil: add Byte and Half-Word width register accessors
> 
> "Byte" and "Half-Word" do not need to be capitalized.  Also, the changelog
> has a typo: "Half-Work" for "half-word".
> 
> >   PCI: mobiveil: make mobiveil_host_init can be used to re-init host
> 
> Here's another of the places that need parens after the function name.
> 
> >   dt-bindings: pci: Add NXP Layerscape SoCs PCIe Gen4 controller
> >   PCI: mobiveil: add PCIe Gen4 RC driver for NXP Layerscape SoCs
> >   PCI: mobiveil: ls_pcie_g4: add Workaround for A-011577
> >   PCI: mobiveil: ls_pcie_g4: add Workaround for A-011451
> 
> The reader of these changelogs likely doesn't know what internal identifiers
> like "A-011577" mean, but *does* want a hint about what problem is being
> fixed and what platforms are affected.  So instead of the "ls_pcie_g4:" 
> prefix,
> use something like:
> 
>   PCI: mobiveil: Work around LX2160A r1.0 config access erratum
>   PCI: mobiveil: Work around LX2160A r1.0 split completion erratum
> 
> and mention the erratum ID (A-011577) in the changelog.  If you can include
> the actual erratum text in the changelog, that would be even better.
> 
> s/ERRATA/errata/ in the changelogs.
> 
> >   arm64: dts: freescale: lx2160a: add pcie DT nodes
> 
> "PCIe"
> 
> >   arm64: defconfig: Enable CONFIG_PCI_LAYERSCAPE_GEN4
> 
> I already asked you once [1] to:
> 
>   please pay attention to the changelog conventions, e.g., capitalize the
>   first word of the sentence ("Remove flag ...", "Correct PCI base address
>   ...", etc), capitalize acronyms like "PCI" and "IRQ", use parentheses
>   after function names, etc.  You can see the conventions by running "git
>   log --oneline drivers/pci/controller".
> 
> For example, instead of this:
> 
>   PCI: mobiveil: add link up condition check
> 
> it should be this:
> 
>   PCI: mobiveil: Add link up condition check
> 
> Please wait at least a few days before posting a v5 in case there are other
> comments.

Thanks for your patience and will fix them in v5.

> 
> Bjorn
> 
> [1]
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.
> kernel.org%2Flinux-pci%2F20190130153447.GB229773%40google.com
> data=02%7C01%7Czhiqiang.hou%40nxp.com%7C591b7c129f0d42caf3b908d6
> a6261d39%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6368790
> 

Re: [PATCH v4 1/3] dt-bindings: phy: Add Stingray USB PHY binding document

2019-03-11 Thread Srinath Mannam
Hi Rob,

Thank you, I will send next patch set with the changes as you suggested.

Regards,
Srinath.
On Tue, Mar 12, 2019 at 3:00 AM Rob Herring  wrote:
>
> On Sun, Mar 10, 2019 at 10:32 PM Srinath Mannam
>  wrote:
> >
> > Hi Rob,
> >
> > Please find my comments below,
> >
> > On Sat, Feb 23, 2019 at 1:05 AM Rob Herring  wrote:
> > >
> > > On Fri, Feb 22, 2019 at 11:29 AM Srinath Mannam
> > >  wrote:
> > > >
> > > > Hi Rob,
> > > >
> > > > Thanks for the review, Please find my comments below in line.
> > > >
> > > > On Fri, Feb 22, 2019 at 10:50 PM Rob Herring  wrote:
> > > > >
> > > > > On Wed, Feb 20, 2019 at 04:04:00PM +0530, Srinath Mannam wrote:
> > > > > > Add DT binding document for Stingray USB PHY.
> > > > > >
> > > > > > Signed-off-by: Srinath Mannam 
> > > > > > Reviewed-by: Florian Fainelli 
> > > > > > Reviewed-by: Scott Branden 
> > > > > > ---
> > > > > >  .../bindings/phy/brcm,stingray-usb-phy.txt | 62 
> > > > > > ++
> > > > > >  1 file changed, 62 insertions(+)
> > > > > >  create mode 100644 
> > > > > > Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt
> > > > > >
> > > > > > diff --git 
> > > > > > a/Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt 
> > > > > > b/Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt
> > > > > > new file mode 100644
> > > > > > index 000..da19236
> > > > > > --- /dev/null
> > > > > > +++ 
> > > > > > b/Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt
> > > > > > @@ -0,0 +1,62 @@
> > > > > > +Broadcom Stingray USB PHY
> > > > > > +
> > > > > > +Required properties:
> > > > > > + - compatible : should be one of the listed compatibles
> > > > > > + - "brcm,sr-usb-combo-phy" is a combo PHY has one SS PHY and 
> > > > > > one HS PHY.
> > > > > > + - "brcm,sr-usb-hs-phy" has a single HS PHY.
> > > > > > + - reg: offset and length of the PHY blocks registers
> > > > > > + - address-cells: should be 1
> > > > > > + - size-cells: should be 0
> > > > > > +
> > > > > > +Sub-nodes:
> > > > > > +  brcm,sr-usb-combo-phy have two sub-nodes for one SS PHY and one 
> > > > > > HS PHY.
> > > > > > +
> > > > > > +Sub-nodes required properties:
> > > > > > + - reg: required for brcm,sr-usb-phy model PHY.
> > > > > > + reg value 0 is HS PHY and 1 is SS PHY.
> > > > > > + - phy-cells: generic PHY binding; must be 0
> > > > > > +
> > > > > > +Refer to phy/phy-bindings.txt for the generic PHY binding 
> > > > > > properties
> > > > > > +
> > > > > > +Example:
> > > > > > + usbphy0: usb-phy@0 {
> > > > > > + compatible = "brcm,sr-usb-combo-phy";
> > > > > > + reg = <0x 0x100>;
> > > > > > + #address-cells = <1>;
> > > > > > + #size-cells = <0>;
> > > > > > +
> > > > > > + usb0_phy0: phy@0 {
> > > > > > + reg = <0>;
> > > > > > + #phy-cells = <0>;
> > > > > > + };
> > > > > > +
> > > > > > + usb0_phy1: phy@1 {
> > > > > > + reg = <1>;
> > > > > > + #phy-cells = <0>;
> > > > > > + };
> > > > >
> > > > > Again, you don't need child nodes here. There are not any per child
> > > > > resources. Clients can refer to < 1> just as easily as
> > > > > <_phy1>. This is why we have #phy-cells.
> > > > This phy controller is combo PHY it has one Super Speed USB PHY and
> > > > one High Speed USB PHY.
> > > > We required to create two PHY devices inside driver to initialize and
> > > > service(reset) both SS and HS PHYs separately.
> > > > That is the reason we used two child nodes.
> > >
> > > What you do in the driver is your business. That is independent of the
> > > binding. Go look at other phy drivers which use #phy-cells=1.
> > > .of_xlate() function is what converts the phy cells to a struct phy.
> > >
> > I have followed exactly same pattern available in open source.
> > ex: Documentation/devicetree/bindings/phy/brcm-sata-phy.txt
> > In this also, two child nodes are used with #phy-cells 0.
>
> You'll notice DT maintainers did not review that binding (only changes
> to it). There's no shortage of DT examples of how not to do things.
>
> Rob


Re: [PATCH 0/4] mm: Use slab_list list_head instead of lru

2019-03-11 Thread Tobin C. Harding
On Mon, Mar 11, 2019 at 07:38:28PM -0700, Matthew Wilcox wrote:
> On Tue, Mar 12, 2019 at 12:05:54PM +1100, Tobin C. Harding wrote:
> > > slab_list and lru are in the same bits.  Once this patch set is in,
> > > we can remove the enigmatic 'uses lru' comment that I added.
> > 
> > Funny you should say this, I came to me today while daydreaming that I
> > should have removed that comment :)
> > 
> > I'll remove it in v2.
> 
> That's great.  BTW, something else you could do to verify this patch
> set is check that the object file is unchanged before/after the patch.
> I tend to use 'objdump -dr' to before.s and after.s and use 'diff'
> to compare the two.

Oh cool, I didn't know to do that.  I'm not super familiar with the use
of unions having never had need to use one myself so any other union
related tips you think of please share.

thanks,
Tobin.


Re: [PATCH v9 1/9] bitops: Introduce the for_each_set_clump8 macro

2019-03-11 Thread Masahiro Yamada
On Sun, Mar 3, 2019 at 4:48 PM William Breathitt Gray
 wrote:
>
> This macro iterates for each 8-bit group of bits (clump) with set bits,
> within a bitmap memory region. For each iteration, "start" is set to the
> bit offset of the found clump, while the respective clump value is
> stored to the location pointed by "clump". Additionally, the
> bitmap_get_value8 and bitmap_set_value8 functions are introduced to
> respectively get and set an 8-bit value in a bitmap memory region.
>
> Suggested-by: Andy Shevchenko 
> Suggested-by: Rasmus Villemoes 
> Cc: Arnd Bergmann 
> Cc: Andrew Morton 
> Reviewed-by: Andy Shevchenko 
> Reviewed-by: Linus Walleij 
> Signed-off-by: William Breathitt Gray 
> ---
>  include/asm-generic/bitops/find.h | 14 ++
>  include/linux/bitops.h|  5 ++
>  lib/find_bit.c| 81 +++
>  3 files changed, 100 insertions(+)
>
> diff --git a/include/asm-generic/bitops/find.h 
> b/include/asm-generic/bitops/find.h
> index 8a1ee10014de..9a76adff59c6 100644
> --- a/include/asm-generic/bitops/find.h
> +++ b/include/asm-generic/bitops/find.h
> @@ -80,4 +80,18 @@ extern unsigned long find_first_zero_bit(const unsigned 
> long *addr,
>
>  #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
>
> +unsigned long bitmap_get_value8(const unsigned long *const bitmap,
> +   const unsigned int size,
> +   const unsigned int start);
> +
> +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size,
> +  const unsigned long value, const unsigned int start);
> +
> +unsigned int find_next_clump8(unsigned long *const clump,
> + const unsigned long *const addr,
> + unsigned int offset, const unsigned int size);
> +
> +#define find_first_clump8(clump, bits, size) \
> +   find_next_clump8((clump), (bits), 0, (size))
> +
>  #endif /*_ASM_GENERIC_BITOPS_FIND_H_ */
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index 705f7c442691..61c10f20079e 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -40,6 +40,11 @@ extern unsigned long __sw_hweight64(__u64 w);
>  (bit) < (size);\
>  (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
>
> +#define for_each_set_clump8(start, clump, bits, size) \
> +   for ((start) = find_first_clump8(&(clump), (bits), (size)); \
> +(start) < (size); \
> +(start) = find_next_clump8(&(clump), (bits), (start) + 8, 
> (size)))
> +
>  static inline int get_bitmask_order(unsigned int count)
>  {
> int order;
> diff --git a/lib/find_bit.c b/lib/find_bit.c
> index ee3df93ba69a..c2af1f013ea2 100644
> --- a/lib/find_bit.c
> +++ b/lib/find_bit.c
> @@ -218,3 +218,84 @@ EXPORT_SYMBOL(find_next_bit_le);
>  #endif
>
>  #endif /* __BIG_ENDIAN */
> +
> +/**
> + * bitmap_get_value8 - get an 8-bit value within a memory region
> + * @bitmap: address to the bitmap memory region
> + * @size: bitmap size in number of bits
> + * @start: bit offset of the 8-bit value
> + *
> + * Returns the 8-bit value located at the @start bit offset within the 
> @bitmap
> + * memory region.
> + */
> +unsigned long bitmap_get_value8(const unsigned long *const bitmap,
> +   const unsigned int size,
> +   const unsigned int start)


A bunch of 'const' qualifiers are eyesore.

The first 'const' of bitmap is the only useful one.


unsigned long bitmap_get_value8(const unsigned long *bitmap, unsigned int size,
unsigned int start)

is enough.





> +{
> +   const size_t index = BIT_WORD(start);
> +   const unsigned int offset = start % BITS_PER_LONG;
> +   const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ?
> +  BITS_PER_LONG - offset : 8;
> +   const unsigned long low = bitmap[index] >> offset;
> +   const unsigned long high = (low_width < 8 && start + 8 <= size) ?
> +  bitmap[index + 1] << low_width : 0;


Meh.



> +
> +   return (low | high) & 0xFF;
> +}
> +EXPORT_SYMBOL(bitmap_get_value8);
> +
> +/**
> + * bitmap_set_value8 - set an 8-bit value within a memory region
> + * @bitmap: address to the bitmap memory region
> + * @size: bitmap size in number of bits
> + * @value: the 8-bit value; values wider than 8 bits may clobber bitmap
> + * @start: bit offset of the 8-bit value
> + */
> +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size,
> +  const unsigned long value, const unsigned int start)
> +{
> +   const size_t index = BIT_WORD(start);
> +   const unsigned int offset = start % BITS_PER_LONG;
> +   const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ?
> +  BITS_PER_LONG - offset : 8;
> +   const 

Some bug fixes to the res sample / script code

2019-03-11 Thread Andi Kleen
Some minor bug fixes to the recently merged res sample / scripting
improvelement in perf report.

-Andi




[PATCH 3/3] perf, tools, report: Set up samples correctly in hierarchy mode

2019-03-11 Thread Andi Kleen
From: Andi Kleen 

In hierarchy mode the res samples need to be cloned from the parent
entry. Copy them in this case. This fixes res sample browsing
with --hierarchy.

Signed-off-by: Andi Kleen 
---
 tools/perf/util/hist.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 1f230285d78a..dcf24581dfbd 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -437,8 +437,15 @@ static int hist_entry__init(struct hist_entry *he,
}
 
if (symbol_conf.res_sample) {
-   he->res_samples = calloc(sizeof(struct res_sample),
-   symbol_conf.res_sample);
+   if (he->res_samples) {
+   he->res_samples = memdup(he->res_samples,
+   sizeof(struct res_sample) *
+   symbol_conf.res_sample);
+   } else {
+   he->res_samples = calloc(sizeof(struct res_sample),
+symbol_conf.res_sample);
+   he->num_res = 0;
+   }
if (!he->res_samples)
goto err_srcline;
}
-- 
2.20.1



[PATCH 2/3] perf, tools, report: Pass on -f to child perf script

2019-03-11 Thread Andi Kleen
From: Andi Kleen 

Pass on -f to the child perf script, so that it can read the perf.data
file if it's owned by a different user.

Signed-off-by: Andi Kleen 
---
 tools/perf/ui/browsers/res_sample.c | 3 ++-
 tools/perf/ui/browsers/scripts.c| 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/ui/browsers/res_sample.c 
b/tools/perf/ui/browsers/res_sample.c
index c450a3536f10..6e17e11a2ab9 100644
--- a/tools/perf/ui/browsers/res_sample.c
+++ b/tools/perf/ui/browsers/res_sample.c
@@ -70,7 +70,7 @@ int res_sample_browse(struct res_sample *res_samples, int 
num_res,
 
attr_to_script(extra_format, >attr);
 
-   if (asprintf(, "%s script %s%s --time %s %s%s %s%s --ns %s %s %s %s 
%s | less +/%s",
+   if (asprintf(, "%s script %s%s --time %s %s%s %s%s --ns %s %s %s %s 
%s %s | less +/%s",
 perf,
 input_name ? "-i " : "",
 input_name ? input_name : "",
@@ -85,6 +85,7 @@ int res_sample_browse(struct res_sample *res_samples, int 
num_res,
 symbol_conf.inline_name ? "--inline" : "",
 "--show-lost-events ",
 r->tid ? "--show-switch-events --show-task-events " : "",
+symbol_conf.force ? "-f" : "",
 tsample) < 0)
return -1;
run_script(cmd);
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index 27cf3ab88d13..f4c438dead66 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -171,12 +171,13 @@ int script_browse(const char *script_opt, struct 
perf_evsel *evsel)
if (list_scripts(script_name, , evsel))
return -1;
 
-   if (asprintf(, "%s%s %s %s%s 2>&1 | less",
+   if (asprintf(, "%s%s %s %s%s %s 2>&1 | less",
custom ? "perf script -s " : "",
script_name,
script_opt ? script_opt : "",
input_name ? "-i " : "",
-   input_name ? input_name : "") < 0)
+   input_name ? input_name : "",
+   symbol_conf.force ? "-f " : "") < 0)
return -1;
 
run_script(cmd);
-- 
2.20.1



[PATCH 1/3] perf, tools, report: Handle samples without time

2019-03-11 Thread Andi Kleen
From: Andi Kleen 

When a sample doesn't have a time stamp (e.g. from --no-time),
show the beginning of the trace for res samples instead of generating
an impossible time range that errors out.

Signed-off-by: Andi Kleen 
---
 tools/perf/ui/browsers/res_sample.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/res_sample.c 
b/tools/perf/ui/browsers/res_sample.c
index c0dd73176d42..c450a3536f10 100644
--- a/tools/perf/ui/browsers/res_sample.c
+++ b/tools/perf/ui/browsers/res_sample.c
@@ -60,7 +60,9 @@ int res_sample_browse(struct res_sample *res_samples, int 
num_res,
return -1;
r = _samples[choice];
 
-   n = timestamp__scnprintf_nsec(r->time - context_len, trange, sizeof 
trange);
+   n = timestamp__scnprintf_nsec(r->time > context_len ?
+ r->time - context_len : r->time,
+ trange, sizeof trange);
trange[n++] = ',';
timestamp__scnprintf_nsec(r->time + context_len, trange + n, sizeof 
trange - n);
 
-- 
2.20.1



Re: [GIT PULL] XArray updates for 5.1-rc1

2019-03-11 Thread pr-tracker-bot
The pull request you sent on Mon, 11 Mar 2019 11:28:29 -0700:

> git://git.infradead.org/users/willy/linux-dax.git xarray

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/ea295481b6e313b4ea3ca2720ffcafd6005b5643

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


Re: [PATCH v3 1/6] x86/mm/KASLR: Improve code comments about struct kaslr_memory_region

2019-03-11 Thread Baoquan He
On 02/18/19 at 11:17am, Baoquan He wrote:
> > > + * When KASLR is active then the MM code makes sure that for each region
> > > + * there's such a single, dynamic, global base address 'unsigned long'
> > > + * variable available for the KASLR code to point to and modify directly:
> > > + *
> > > + * { _offset_base, 0 },
> > > + * { _base, 0 },
> > > + * { _base, 1 },
> > > + *
> > > + * @size_tb: size in TB of each memory region. Thereinto, the size of
> > 
> > nit: "Thereinto" is odd. I'd say "Therefore".


Recheck here, there might be a misunderstanding. Here, 'Thereinto', I
want to say among the sizes of these three memory regions, the size of
the physical memory mapping region is variable. Just look it up in dict,
it sounds right. 'Therefore' equals to 'Hence' which is not expected
here. Am I right?
> 
> Will replace it with 'Therefore'.
> 
> > 
> > > + * the physical memory mapping region is variable, calculated according
> > > + * to the actual size of system RAM in order to save more space for
> > > + * randomization. The rest are fixed values related to paging mode.
> > > + *
> > > + * @size_tb: is the size of each memory region after randomization, and
> > > + * its unit is TB.


Re: [PATCH 1/2] PM / wakeup: Remove timer from wakeup_source_remove()

2019-03-11 Thread Viresh Kumar
On 11-03-19, 13:05, Rafael J. Wysocki wrote:
> On Friday, March 8, 2019 10:53:11 AM CET Viresh Kumar wrote:
> > wakeup_source_remove() is the counterpart of wakeup_source_add() helper
> > and must undo the initializations done by wakeup_source_add(). Currently
> > the timer is initialized by wakeup_source_add() but removed from
> > wakeup_source_drop(), which doesn't look logically correct. Also it
> > should be okay to call wakeup_source_add() right after calling
> > wakeup_source_remove(), and in that case we may end up calling
> > timer_setup() for a potentially scheduled timer which is surely
> > incorrect.
> > 
> > Move the timer removal part to wakeup_source_remove() instead.
> > 
> > Signed-off-by: Viresh Kumar 
> > ---
> >  drivers/base/power/wakeup.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> > index f1fee72ed970..18333962e3da 100644
> > --- a/drivers/base/power/wakeup.c
> > +++ b/drivers/base/power/wakeup.c
> > @@ -118,7 +118,6 @@ void wakeup_source_drop(struct wakeup_source *ws)
> > if (!ws)
> > return;
> >  
> > -   del_timer_sync(>timer);
> > __pm_relax(ws);
> >  }
> >  EXPORT_SYMBOL_GPL(wakeup_source_drop);
> > @@ -205,6 +204,8 @@ void wakeup_source_remove(struct wakeup_source *ws)
> > list_del_rcu(>entry);
> > raw_spin_unlock_irqrestore(_lock, flags);
> > synchronize_srcu(_srcu);
> > +
> > +   del_timer_sync(>timer);
> >  }
> >  EXPORT_SYMBOL_GPL(wakeup_source_remove);
> >  
> > 
> 
> I've merged it with the [2/2], rewritten the subject and changelog and
> queued the result as commit d856f39ac1cc ("PM / wakeup: Rework wakeup
> source timer cancellation").

Okay, thanks. We (Android guys) want this to be backported into 4.4+
kernels via the stable tree. Can we mark this for stable in the commit
itself ? Else I would be required to send this separately for all the
kernels. I should have marked it for stable initially though, sorry
about forgetting then.

-- 
viresh


[PATCH v4 23/31] docs/zh_CN: update Zhang Wei's email address

2019-03-11 Thread Alex Shi
to replace the obsolete email address with new one.

Signed-off-by: Alex Shi 
Cc: Zhang Wei 
Cc: Li Yang 
Signed-off-by: Weiwei Jia 
---
 Documentation/translations/zh_CN/process/submitting-drivers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/translations/zh_CN/process/submitting-drivers.rst 
b/Documentation/translations/zh_CN/process/submitting-drivers.rst
index fade72515b04..43c0e4530362 100644
--- a/Documentation/translations/zh_CN/process/submitting-drivers.rst
+++ b/Documentation/translations/zh_CN/process/submitting-drivers.rst
@@ -13,7 +13,7 @@
 中文版翻译者: 李阳  Li Yang 
 中文版校译者: 陈琦 Maggie Chen 
王聪 Wang Cong 
-   张巍 Zhang Wei 
+   张巍 Zhang Wei 
 
 如何向 Linux 内核提交驱动程序
 =
-- 
2.19.1.856.g8858448bb



Re: [PATCH] PM / wakeup: Drop wakeup_source_drop()

2019-03-11 Thread Viresh Kumar
On 11-03-19, 12:53, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki 
> 
> After commit d856f39ac1cc ("PM / wakeup: Rework wakeup source timer
> cancellation") wakeup_source_drop() is a trivial wrapper around
> __pm_relax() and it has no users except for wakeup_source_destroy()
> and wakeup_source_trash() which also has no users, so drop it along
> with the latter and make wakeup_source_destroy() call __pm_relax()
> directly.
> 
> Signed-off-by: Rafael J. Wysocki 
> ---
> 
> Commit d856f39ac1cc is in the bleeding-edge branch of the linux-pm.git tree.
> 
> ---
>  drivers/base/power/wakeup.c |   18 +-
>  include/linux/pm_wakeup.h   |9 -
>  2 files changed, 1 insertion(+), 26 deletions(-)

Acked-by: Viresh Kumar 

-- 
viresh


[PATCH v4 08/31] docs/zh_CN: format the submitting-patches doc to rst

2019-03-11 Thread Alex Shi
And remove Enghlish explainations in the docs, which it isn't
necessary in Chinese doc.

Signed-off-by: Alex Shi 
Cc: Harry Wei 
Cc: Jonathan Corbet 
Cc: TripleX Chung 
Cc: Li Zefan 
Cc: Shawn Guo 
Cc: Fengguang Wu 
Cc: Coly Li 
Signed-off-by: Weiwei Jia 
---
 .../zh_CN/process/submitting-patches.rst  | 36 +++
 1 file changed, 13 insertions(+), 23 deletions(-)

diff --git a/Documentation/translations/zh_CN/process/submitting-patches.rst 
b/Documentation/translations/zh_CN/process/submitting-patches.rst
index e9098da8f1a4..2a2989733c8d 100644
--- a/Documentation/translations/zh_CN/process/submitting-patches.rst
+++ b/Documentation/translations/zh_CN/process/submitting-patches.rst
@@ -1,31 +1,21 @@
-Chinese translated version of Documentation/process/submitting-patches.rst
+.. _cn_process_submittingpatches:
 
-If you have any comment or update to the content, please contact the
-original document maintainer directly.  However, if you have a problem
-communicating in English you can also ask the Chinese maintainer for
-help.  Contact the Chinese maintainer if this translation is outdated
-or if there is a problem with the translation.
+.. include:: ../disclaimer-zh_CN.rst
 
-Chinese maintainer: TripleX Chung 
--
-Documentation/process/submitting-patches.rst 的中文翻译
+:Original: :ref:`Documentation/process/submitting-patches.rst 
`
 
 如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
 交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
-译存在问题,请联系中文版维护者。
+译存在问题,请联系中文版维护者::
 
-中文版维护者: 钟宇 TripleX Chung 
-中文版翻译者: 钟宇 TripleX Chung 
-中文版校译者: 李阳 Li Yang 
-   王聪 Wang Cong 
+中文版维护者: 钟宇 TripleX Chung 
+中文版翻译者: 钟宇 TripleX Chung 
+中文版校译者: 李阳 Li Yang 
+   王聪 Wang Cong 
 
-以下为正文
--
 
-   如何让你的改动进入内核
- 或者
-  获得亲爱的 Linus Torvalds 的关注和处理
---
+如何让你的改动进入内核
+==
 
 对于想要将改动提交到 Linux 内核的个人或者公司来说,如果不熟悉“规矩”,
 提交的流程会让人畏惧。本文档收集了一系列建议,这些建议可以大大的提高你
@@ -35,12 +25,12 @@ Documentation/process/submitting-patches.rst 的中文翻译
 Documentation/process/submitting-drivers.rst 。
 
 
---
+---
 第一节 - 创建并发送你的改动
---
+---
 
 1) "diff -up"

+-
 
 使用 "diff -up" 或者 "diff -uprN" 来创建补丁。
 
-- 
2.19.1.856.g8858448bb



[PATCH 1/1] initrd: move initrd_start calculate within linear mapping range check

2019-03-11 Thread pierre Kuo
in the previous case, initrd_start and initrd_end can be successfully
returned even (base < memblock_start_of_DRAM()) or (base + size >
memblock_start_of_DRAM() + linear_region_size).

That means even linear mapping range check fail for initrd_start and
initrd_end, it still can get virtual address. Here we put
initrd_start/initrd_end to be calculated only when linear mapping check
pass.

Signed-off-by: pierre Kuo 
---
 arch/arm64/mm/init.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 7205a9085b4d..1adf418de685 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -425,6 +425,9 @@ void __init arm64_memblock_init(void)
memblock_remove(base, size); /* clear MEMBLOCK_ flags */
memblock_add(base, size);
memblock_reserve(base, size);
+   /* the generic initrd code expects virtual addresses */
+   initrd_start = __phys_to_virt(phys_initrd_start);
+   initrd_end = initrd_start + phys_initrd_size;
}
}
 
@@ -450,11 +453,6 @@ void __init arm64_memblock_init(void)
 * pagetables with memblock.
 */
memblock_reserve(__pa_symbol(_text), _end - _text);
-   if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && phys_initrd_size) {
-   /* the generic initrd code expects virtual addresses */
-   initrd_start = __phys_to_virt(phys_initrd_start);
-   initrd_end = initrd_start + phys_initrd_size;
-   }
 
early_init_fdt_scan_reserved_mem();
 
-- 
2.17.1



RE: [PATCHv4 23/28] dt-bindings: pci: Add NXP Layerscape SoCs PCIe Gen4 controller

2019-03-11 Thread Z.q. Hou
Hi Rob,

> -Original Message-
> From: Rob Herring [mailto:r...@kernel.org]
> Sent: 2019年3月12日 6:12
> To: Z.q. Hou 
> Cc: linux-...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; linux-kernel@vger.kernel.org;
> bhelg...@google.com; robh...@kernel.org; mark.rutl...@arm.com;
> l.subrahma...@mobiveil.co.in; shawn...@kernel.org; Leo Li
> ; lorenzo.pieral...@arm.com;
> catalin.mari...@arm.com; will.dea...@arm.com; Mingkai Hu
> ; M.h. Lian ; Xiaowei Bao
> ; Z.q. Hou 
> Subject: Re: [PATCHv4 23/28] dt-bindings: pci: Add NXP Layerscape SoCs PCIe
> Gen4 controller
> 
> On Mon, 11 Mar 2019 09:33:05 +, "Z.q. Hou" wrote:
> > From: Hou Zhiqiang 
> >
> > Add PCIe Gen4 controller DT bindings of NXP Layerscape SoCs.
> >
> > Signed-off-by: Hou Zhiqiang 
> > ---
> > V4:
> >  - no change
> >
> >  .../bindings/pci/layerscape-pci-gen4.txt  | 52
> +++
> >  MAINTAINERS   |  8 +++
> >  2 files changed, 60 insertions(+)
> >  create mode 100644
> > Documentation/devicetree/bindings/pci/layerscape-pci-gen4.txt
> >
> 
> Please add Acked-by/Reviewed-by tags when posting new versions. However,
> there's no need to repost patches *only* to add the tags. The upstream
> maintainer will do that for acks received on the version they apply.
> 
> If a tag was not added on purpose, please state why and what changed.

Sorry, I missed your Reviewed-by tag in this patch, will re-send this patch 
adding the lost tag.

Thanks,
Zhiqiang


Re: [PATCH 09/10] mm/hmm: allow to mirror vma of a file on a DAX backed filesystem

2019-03-11 Thread Dan Williams
On Thu, Mar 7, 2019 at 10:56 AM Jerome Glisse  wrote:
>
> On Thu, Mar 07, 2019 at 09:46:54AM -0800, Andrew Morton wrote:
> > On Tue, 5 Mar 2019 20:20:10 -0800 Dan Williams  
> > wrote:
> >
> > > My hesitation would be drastically reduced if there was a plan to
> > > avoid dangling unconsumed symbols and functionality. Specifically one
> > > or more of the following suggestions:
> > >
> > > * EXPORT_SYMBOL_GPL on all exports to avoid a growing liability
> > > surface for out-of-tree consumers to come grumble at us when we
> > > continue to refactor the kernel as we are wont to do.
> >
> > The existing patches use EXPORT_SYMBOL() so that's a sticking point.
> > Jerome, what would happen is we made these EXPORT_SYMBOL_GPL()?
>
> So Dan argue that GPL export solve the problem of out of tree user and
> my personnal experience is that it does not. The GPU sub-system has tons
> of GPL drivers that are not upstream and we never felt that we were bound
> to support them in anyway. We always were very clear that if you are not
> upstream that you do not have any voice on changes we do.
>
> So my exeperience is that GPL does not help here. It is just about being
> clear and ignoring anyone who does not have an upstream driver ie we have
> free hands to update HMM in anyway as long as we keep supporting the
> upstream user.
>
> That being said if the GPL aspect is that much important to some then
> fine let switch all HMM symbol to GPL.

I should add that I would not be opposed to moving symbols to
non-GPL-only over time, but that should be based on our experience
with the stability and utility of the implementation. For brand new
symbols there's just no data to argue that we can / should keep the
interface stable, or that the interface exposes something fragile that
we'd rather not export at all. That experience gathering and thrash is
best constrained to upstream GPL-only drivers that are signing up to
participate in that maturation process.

So I think it is important from a practical perspective and is a lower
risk way to run this HMM experiment of "merge infrastructure way in
advance of an upstream user".

> > > * A commitment to consume newly exported symbols in the same merge
> > > window, or the following merge window. When that goal is missed revert
> > > the functionality until such time that it can be consumed, or
> > > otherwise abandoned.
> >
> > It sounds like we can tick this box.
>
> I wouldn't be too strick either, when adding something in release N
> the driver change in N+1 can miss N+1 because of bug or regression
> and be push to N+2.
>
> I think a better stance here is that if we do not get any sign-off
> on the feature from driver maintainer for which the feature is intended
> then we just do not merge.

Agree, no driver maintainer sign-off then no merge.

> If after few release we still can not get
> the driver to use it then we revert.

As long as it is made clear to the driver maintainer that they have
one cycle to consume it then we can have a conversation if it is too
early to merge the infrastructure. If no one has time to consume the
feature, why rush dead code into the kernel? Also, waiting 2 cycles
means the infrastructure that was hard to review without a user is now
even harder to review because any review momentum has been lost by the
time the user show up, so we're better off keeping them close together
in time.


> It just feels dumb to revert at N+1 just to get it back in N+2 as
> the driver bit get fix.

No, I think it just means the infrastructure went in too early if a
driver can't consume it in a development cycle. Lets revisit if it
becomes a problem in practice.

> > > * No new symbol exports and functionality while existing symbols go 
> > > unconsumed.
> >
> > Unsure about this one?
>
> With nouveau upstream now everything is use. ODP will use some of the
> symbol too. PPC has patchset posted to use lot of HMM too. I have been
> working with other vendor that have patchset being work on to use HMM
> too.
>
> I have not done all those function just for the fun of it :) They do
> have real use and user. It took a longtime to get nouveau because of
> userspace we had a lot of catchup to do in mesa and llvm and we are
> still very rough there.

Sure, this one is less of a concern if we can stick to tighter
timelines between infrastructure and driver consumer merge.


Re: [RFC PATCH v1 19/25] printk: introduce emergency messages

2019-03-11 Thread Sergey Senozhatsky
On (03/08/19 11:31), Petr Mladek wrote:
> Great catch!
> 
> I think that it is doable to guard the list using RCU.

I think console_sem is more than just list lock.

E.g. fb_flashcursor() - console_sem protects framebuffer from concurrent
modifications. And many other examples.

I think the last time we talked about it (two+ years ago) we counted
5 or 7 (don't remember exactly) different things which console_sem
does.

-ss


Re: [RFC PATCH v1 19/25] printk: introduce emergency messages

2019-03-11 Thread Sergey Senozhatsky
On (03/11/19 13:04), John Ogness wrote:
> > Great catch!
> 
> Yes, thanks!
> 
> > I think that it is doable to guard the list using RCU.
> 
> I think it would be enough to take the prb_cpulock when modifying the
> console linked list. That will keep printk_emergency() out until the
> list has been updated. (registering/unregistering consoles is not
> something that happens often.)

console_sem can be a bit more than just registering/unregistering.
Especially when it comes to VT, fbcon and ioctls.

$ git grep console_lock drivers/tty/ | wc -l
82

$ git grep console_lock drivers/video/fbdev/ | wc -l
80

-ss


Re: [PATCH 29/42] drivers: gpio: sprd: use devm_platform_ioremap_resource()

2019-03-11 Thread Baolin Wang
Hi,
On Tue, 12 Mar 2019 at 02:57, Enrico Weigelt, metux IT consult
 wrote:
>
> Use the new helper that wraps the calls to platform_get_resource()
> and devm_ioremap_resource() together.
>
> Signed-off-by: Enrico Weigelt, metux IT consult 
> ---
>  drivers/gpio/gpio-sprd.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpio-sprd.c b/drivers/gpio/gpio-sprd.c
> index 55072d2..f5c8b3a 100644
> --- a/drivers/gpio/gpio-sprd.c
> +++ b/drivers/gpio/gpio-sprd.c
> @@ -219,7 +219,6 @@ static int sprd_gpio_probe(struct platform_device *pdev)
>  {
> struct gpio_irq_chip *irq;
> struct sprd_gpio *sprd_gpio;
> -   struct resource *res;
> int ret;
>
> sprd_gpio = devm_kzalloc(>dev, sizeof(*sprd_gpio), GFP_KERNEL);
> @@ -232,8 +231,7 @@ static int sprd_gpio_probe(struct platform_device *pdev)
> return sprd_gpio->irq;
> }
>
> -   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -   sprd_gpio->base = devm_ioremap_resource(>dev, res);
> +   sprd_gpio->base = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(sprd_gpio->base))
> return PTR_ERR(sprd_gpio->base);
>

Thanks for your patch.

Reviewed-by: Baolin Wang 

-- 
Baolin Wang
Best Regards


Re: [PATCH 09/42] drivers: gpio: sprd: use devm_platform_ioremap_resource()

2019-03-11 Thread Baolin Wang
On Tue, 12 Mar 2019 at 02:55, Enrico Weigelt, metux IT consult
 wrote:
>
> Use the new helper that wraps the calls to platform_get_resource()
> and devm_ioremap_resource() together.
>
> Signed-off-by: Enrico Weigelt, metux IT consult 
> ---
>  drivers/gpio/gpio-eic-sprd.c | 9 ++---
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpio/gpio-eic-sprd.c b/drivers/gpio/gpio-eic-sprd.c
> index f0223ce..c12de87 100644
> --- a/drivers/gpio/gpio-eic-sprd.c
> +++ b/drivers/gpio/gpio-eic-sprd.c
> @@ -567,7 +567,6 @@ static int sprd_eic_probe(struct platform_device *pdev)
> const struct sprd_eic_variant_data *pdata;
> struct gpio_irq_chip *irq;
> struct sprd_eic *sprd_eic;
> -   struct resource *res;
> int ret, i;
>
> pdata = of_device_get_match_data(>dev);
> @@ -596,13 +595,9 @@ static int sprd_eic_probe(struct platform_device *pdev)
>  * have one bank EIC, thus base[1] and base[2] can be
>  * optional.
>  */
> -   res = platform_get_resource(pdev, IORESOURCE_MEM, i);
> -   if (!res)
> -   continue;
> -
> -   sprd_eic->base[i] = devm_ioremap_resource(>dev, res);
> +   sprd_eic->base[i] = devm_platform_ioremap_resource(pdev, 0);

This is incorrect, since we can have multiple IO resources, but you
only get index 0.

> if (IS_ERR(sprd_eic->base[i]))
> -   return PTR_ERR(sprd_eic->base[i]);
> +   continue;
> }
>
> sprd_eic->chip.label = sprd_eic_label_name[sprd_eic->type];
> --
> 1.9.1
>
-- 
Baolin Wang
Best Regards


Re: [PATCH v6 1/2] dt-bindings: misc: aspeed-p2a-ctrl: add support

2019-03-11 Thread Rob Herring
On Mon, Mar 11, 2019 at 6:49 PM Patrick Venture  wrote:
>
> On Mon, Mar 11, 2019 at 3:20 PM Rob Herring  wrote:
> >
> > On Mon, Mar 04, 2019 at 10:55:36AM -0800, Patrick Venture wrote:
> > > Document the ast2400, ast2500 PCI-to-AHB bridge control driver bindings.
> > >
> > > Signed-off-by: Patrick Venture 
> > > ---
> > > Changes for v6:
> > > - None
> > > Changes for v5:
> > > - None
> > > Changes for v4:
> > > - None
> > > Changes for v3:
> > > - None
> > > Changes for v2:
> > > - Added comment about syscon required parameter.
> > > ---
> > >  .../bindings/misc/aspeed-p2a-ctrl.txt | 32 +++
> > >  1 file changed, 32 insertions(+)
> > >  create mode 100644 
> > > Documentation/devicetree/bindings/misc/aspeed-p2a-ctrl.txt
> > >
> > > diff --git a/Documentation/devicetree/bindings/misc/aspeed-p2a-ctrl.txt 
> > > b/Documentation/devicetree/bindings/misc/aspeed-p2a-ctrl.txt
> > > new file mode 100644
> > > index ..1092d62d1c92
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/misc/aspeed-p2a-ctrl.txt
> > > @@ -0,0 +1,32 @@
> > > +==
> > > +Device tree bindings for Aspeed AST2400/AST2500 PCI-to-AHB Bridge 
> > > Control Driver
> > > +==
> > > +
> > > +The bridge is available on platforms with the VGA enabled on the Aspeed 
> > > device.
> > > +In this case, the host has access to a 64KiB window into all of the BMC's
> > > +memory.  The BMC can disable this bridge.  If the bridge is enabled, the 
> > > host
> > > +has read access to all the regions of memory, however the host only has 
> > > read
> > > +and write access depending on a register controlled by the BMC.
> > > +
> > > +Required properties:
> > > +===
> > > +
> > > + - compatible: must be one of:
> > > + - "aspeed,ast2400-p2a-ctrl"
> > > + - "aspeed,ast2500-p2a-ctrl"
> > > +
> > > + - syscon: handle to syscon device node controlling PCI.
> > > +
> > > +Optional properties:
> > > +===
> > > +
> > > +- memory-region: A phandle to a reserved_memory region to be used for 
> > > the PCI
> > > + to AHB mapping
> > > +
> > > +Example:
> > > +
> > > +p2a: p2a-control@1e6e2000 {
> > > + compatible = "aspeed,ast2400-p2a-ctrl";
> > > + memory-region = <_memory>;
> > > + syscon = <>;
> >
> > Make this node a child of what you are pointing to instead if this the
> > only control interface.
>
> You're suggesting I make this a child of the syscon?

Yes.

Rob


Re: [PATCH 0/4] mm: Use slab_list list_head instead of lru

2019-03-11 Thread Matthew Wilcox
On Tue, Mar 12, 2019 at 12:05:54PM +1100, Tobin C. Harding wrote:
> > slab_list and lru are in the same bits.  Once this patch set is in,
> > we can remove the enigmatic 'uses lru' comment that I added.
> 
> Funny you should say this, I came to me today while daydreaming that I
> should have removed that comment :)
> 
> I'll remove it in v2.

That's great.  BTW, something else you could do to verify this patch
set is check that the object file is unchanged before/after the patch.
I tend to use 'objdump -dr' to before.s and after.s and use 'diff'
to compare the two.


Re: [PATCH] arm64: dts: fsl: imx8mq: enable the thermal management unit (TMU)

2019-03-11 Thread Andrey Smirnov
On Mon, Mar 11, 2019 at 2:35 PM Angus Ainslie (Purism)  wrote:
>
> These are the TMU nodes from the NXP vendor kernel
>

Hey Angus,

TMU block supports multiple thermal zones and vendor kernel doesn't
really account for that (see below). Latest version of the driver in
thermal tree now actually supports that feature (mulit-sensor), so I
think the code in DT should reflect that as well. I recently submitted
a series adding HWMON integration for TMU
(https://lore.kernel.org/lkml/2019000508.26325-1-andrew.smir...@gmail.com/T/#u)
and this is my take on this patch:

https://github.com/ndreys/linux/commit/09931e3d60af0a74377307b433db97da1be31570

All of the code there is up for grabs, if you feel like using it.

> Signed-off-by: Angus Ainslie (Purism) 
> ---
>  arch/arm64/boot/dts/freescale/imx8mq.dtsi | 83 +++
>  1 file changed, 83 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
> b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
> index 9155bd4784eb..087620c6e17f 100644
> --- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
> +++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
> @@ -8,6 +8,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include "imx8mq-pinfunc.h"
>
>  / {
> @@ -89,6 +90,7 @@
> reg = <0x0>;
> enable-method = "psci";
> next-level-cache = <_L2>;
> +   #cooling-cells = <2>;
> };
>
> A53_1: cpu@1 {
> @@ -210,6 +212,87 @@
> #interrupt-cells = <2>;
> };
>
> +   tmu: tmu@3026 {
> +   compatible = "fsl,imx8mq-tmu";
> +   reg = <0x3026 0x1>;
> +   interrupt = ;
> +   little-endian;
> +   fsl,tmu-range = <0xb 0xa0026 0x80048 
> 0x70061>;
> +   fsl,tmu-calibration = <0x 0x0023
> +  0x0001 0x0029
> +  0x0002 0x002f
> +  0x0003 0x0035
> +  0x0004 0x003d
> +  0x0005 0x0043
> +  0x0006 0x004b
> +  0x0007 0x0051
> +  0x0008 0x0057
> +  0x0009 0x005f
> +  0x000a 0x0067
> +  0x000b 0x006f
> +
> +  0x0001 0x001b
> +  0x00010001 0x0023
> +  0x00010002 0x002b
> +  0x00010003 0x0033
> +  0x00010004 0x003b
> +  0x00010005 0x0043
> +  0x00010006 0x004b
> +  0x00010007 0x0055
> +  0x00010008 0x005d
> +  0x00010009 0x0067
> +  0x0001000a 0x0070
> +
> +  0x0002 0x0017
> +  0x00020001 0x0023
> +  0x00020002 0x002d
> +  0x00020003 0x0037
> +  0x00020004 0x0041
> +  0x00020005 0x004b
> +  0x00020006 0x0057
> +  0x00020007 0x0063
> +  0x00020008 0x006f
> +
> +  0x0003 0x0015
> +  0x00030001 0x0021
> +  0x00030002 0x002d
> +  0x00030003 0x0039
> +  0x00030004 0x0045
> +  0x00030005 0x0053
> +

Re: [PATCH v2 3/9] dt-bindings: mfd: Add compatible for the MediaTek MT6358 PMIC

2019-03-11 Thread Sean Wang
On Mon, Mar 11, 2019 at 3:06 PM Rob Herring  wrote:
>
> On Mon, Mar 11, 2019 at 12:19:32PM -0700, Sean Wang wrote:
> > Hi,
> >
> > Always put the patches about dt-binding changes at the head of the
> > series to let the related maintainer more easily find them.
> >
> > On Sun, Mar 10, 2019 at 8:48 PM Hsin-Hsiung Wang
> >  wrote:
> > >
> > > This adds compatible for the MediaTek MT6358 PMIC.
> > >
> > > Signed-off-by: Hsin-Hsiung Wang 
> > > ---
> > >  Documentation/devicetree/bindings/mfd/mt6397.txt | 11 ---
> > >  1 file changed, 8 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/Documentation/devicetree/bindings/mfd/mt6397.txt 
> > > b/Documentation/devicetree/bindings/mfd/mt6397.txt
> > > index 0ebd08a..62f1c17 100644
> > > --- a/Documentation/devicetree/bindings/mfd/mt6397.txt
> > > +++ b/Documentation/devicetree/bindings/mfd/mt6397.txt
> > > @@ -17,22 +17,27 @@ 
> > > Documentation/devicetree/bindings/soc/mediatek/pwrap.txt
> > >  This document describes the binding for MFD device and its sub module.
> > >
> > >  Required properties:
> > > -compatible: "mediatek,mt6397" or "mediatek,mt6323"
> > > +compatible:
> > > +   "mediatek,mt6323" for PMIC MT6323
> > > +   "mediatek,mt6358" for PMIC MT6358
> > > +   "mediatek,mt6397" for PMIC MT6397
> >
> > don't change anything not related MT6358
>
> Reformatting like this is preferred.
>

Sure, it's fine to me for the purpose.

> Rob


[PATCH V5 3/4] ARM: dts: imx: make MMDC node name generic

2019-03-11 Thread Anson Huang
Node name should be generic, so use "memory-controller"
instead of "mmdc" for MMDC node name, also remove "mmdc"
label for platforms with single MMDC node.

Signed-off-by: Anson Huang 
Reviewed-by: Fabio Estevam 
---
No changes.
---
 arch/arm/boot/dts/imx6qdl.dtsi | 4 ++--
 arch/arm/boot/dts/imx6sl.dtsi  | 2 +-
 arch/arm/boot/dts/imx6sx.dtsi  | 2 +-
 arch/arm/boot/dts/imx6ul.dtsi  | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index fe17a34..4c7278b 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1129,13 +1129,13 @@
reg = <0x021ac000 0x4000>;
};
 
-   mmdc0: mmdc@21b { /* MMDC0 */
+   mmdc0: memory-controller@21b { /* MMDC0 */
compatible = "fsl,imx6q-mmdc";
reg = <0x021b 0x4000>;
clocks = < IMX6QDL_CLK_MMDC_P0_IPG>;
};
 
-   mmdc1: mmdc@21b4000 { /* MMDC1 */
+   mmdc1: memory-controller@21b4000 { /* MMDC1 */
reg = <0x021b4000 0x4000>;
};
 
diff --git a/arch/arm/boot/dts/imx6sl.dtsi b/arch/arm/boot/dts/imx6sl.dtsi
index 4b4813f..733ea50 100644
--- a/arch/arm/boot/dts/imx6sl.dtsi
+++ b/arch/arm/boot/dts/imx6sl.dtsi
@@ -922,7 +922,7 @@
status = "disabled";
};
 
-   mmdc: mmdc@21b {
+   memory-controller@21b {
compatible = "fsl,imx6sl-mmdc", 
"fsl,imx6q-mmdc";
reg = <0x021b 0x4000>;
clocks = < IMX6SL_CLK_MMDC_P0_IPG>;
diff --git a/arch/arm/boot/dts/imx6sx.dtsi b/arch/arm/boot/dts/imx6sx.dtsi
index 5b16e65..df0c595 100644
--- a/arch/arm/boot/dts/imx6sx.dtsi
+++ b/arch/arm/boot/dts/imx6sx.dtsi
@@ -1017,7 +1017,7 @@
status = "disabled";
};
 
-   mmdc: mmdc@21b {
+   memory-controller@21b {
compatible = "fsl,imx6sx-mmdc", 
"fsl,imx6q-mmdc";
reg = <0x021b 0x4000>;
clocks = < IMX6SX_CLK_MMDC_P0_IPG>;
diff --git a/arch/arm/boot/dts/imx6ul.dtsi b/arch/arm/boot/dts/imx6ul.dtsi
index 62ed30c..a77bbca 100644
--- a/arch/arm/boot/dts/imx6ul.dtsi
+++ b/arch/arm/boot/dts/imx6ul.dtsi
@@ -914,7 +914,7 @@
status = "disabled";
};
 
-   mmdc: mmdc@21b {
+   memory-controller@21b {
compatible = "fsl,imx6ul-mmdc", 
"fsl,imx6q-mmdc";
reg = <0x021b 0x4000>;
clocks = < IMX6UL_CLK_MMDC_P0_IPG>;
-- 
2.7.4



[PATCH V5 4/4] ARM: dts: imx6qdl: Improve mmdc1 node

2019-03-11 Thread Anson Huang
Add MMDC1 compatible string which is missing, and also set
it to be disabled by default, as most of the platforms ONLY
use single channel MMDC0, if dual MMDC channels are used, it
can be enabled in board dts file.

Signed-off-by: Anson Huang 
---
New patch.
---
 arch/arm/boot/dts/imx6qdl.dtsi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 4c7278b..8c51364 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1136,7 +1136,9 @@
};
 
mmdc1: memory-controller@21b4000 { /* MMDC1 */
+   compatible = "fsl,imx6q-mmdc";
reg = <0x021b4000 0x4000>;
+   status = "disabled";
};
 
weim: weim@21b8000 {
-- 
2.7.4



[PATCH v2 2/5] drm/amd: fix fb references in async update

2019-03-11 Thread Helen Koike
Async update callbacks are expected to set the old_fb in the new_state
so prepare/cleanup framebuffers are balanced.

Calling drm_atomic_set_fb_for_plane() (which gets a reference of the new
fb and put the old fb) is not required, as it's taken care by
drm_mode_cursor_universal() when calling drm_atomic_helper_update_plane().

Suggested-by: Boris Brezillon 
Signed-off-by: Helen Koike 
Reviewed-by: Nicholas Kazlauskas 

---

Changes in v2:
- added reviewed-by tag

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 3a6f595f295e..bc02800254bf 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3760,8 +3760,7 @@ static void dm_plane_atomic_async_update(struct drm_plane 
*plane,
struct drm_plane_state *old_state =
drm_atomic_get_old_plane_state(new_state->state, plane);
 
-   if (plane->state->fb != new_state->fb)
-   drm_atomic_set_fb_for_plane(plane->state, new_state->fb);
+   swap(plane->state->fb, new_state->fb);
 
plane->state->src_x = new_state->src_x;
plane->state->src_y = new_state->src_y;
-- 
2.20.1



[PATCH V5 1/4] dt-bindings: memory-controllers: freescale: add MMDC binding doc

2019-03-11 Thread Anson Huang
Freescale MMDC (Multi Mode DDR Controller) driver is supported
since i.MX6Q, but not yet documented, this patch adds binding
doc for MMDC module driver.

Signed-off-by: Anson Huang 
---
Changes since V4:
- update mmdc1 example.
---
 .../bindings/memory-controllers/fsl/mmdc.txt   | 35 ++
 1 file changed, 35 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/memory-controllers/fsl/mmdc.txt

diff --git a/Documentation/devicetree/bindings/memory-controllers/fsl/mmdc.txt 
b/Documentation/devicetree/bindings/memory-controllers/fsl/mmdc.txt
new file mode 100644
index 000..bcc36c5
--- /dev/null
+++ b/Documentation/devicetree/bindings/memory-controllers/fsl/mmdc.txt
@@ -0,0 +1,35 @@
+Freescale Multi Mode DDR controller (MMDC)
+
+Required properties :
+- compatible : should be one of following:
+   for i.MX6Q/i.MX6DL:
+   - "fsl,imx6q-mmdc";
+   for i.MX6QP:
+   - "fsl,imx6qp-mmdc", "fsl,imx6q-mmdc";
+   for i.MX6SL:
+   - "fsl,imx6sl-mmdc", "fsl,imx6q-mmdc";
+   for i.MX6SLL:
+   - "fsl,imx6sll-mmdc", "fsl,imx6q-mmdc";
+   for i.MX6SX:
+   - "fsl,imx6sx-mmdc", "fsl,imx6q-mmdc";
+   for i.MX6UL/i.MX6ULL/i.MX6ULZ:
+   - "fsl,imx6ul-mmdc", "fsl,imx6q-mmdc";
+   for i.MX7ULP:
+   - "fsl,imx7ulp-mmdc", "fsl,imx6q-mmdc";
+- reg : address and size of MMDC DDR controller registers
+
+Optional properties :
+- clocks : the clock provided by the SoC to access the MMDC registers
+
+Example :
+   mmdc0: memory-controller@21b { /* MMDC0 */
+   compatible = "fsl,imx6q-mmdc";
+   reg = <0x021b 0x4000>;
+   clocks = < IMX6QDL_CLK_MMDC_P0_IPG>;
+   };
+
+   mmdc1: memory-controller@21b4000 { /* MMDC1 */
+   compatible = "fsl,imx6q-mmdc";
+   reg = <0x021b4000 0x4000>;
+   status = "disabled";
+   };
-- 
2.7.4



[PATCH V5 2/4] ARM: dts: imx7ulp: add mmdc support

2019-03-11 Thread Anson Huang
i.MX7ULP has a MMDC module to control DDR, it reuses
i.MX6Q's MMDC module, add support for it.

Signed-off-by: Anson Huang 
Reviewed-by: Fabio Estevam 
---
No changes.
---
 arch/arm/boot/dts/imx7ulp.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/imx7ulp.dtsi b/arch/arm/boot/dts/imx7ulp.dtsi
index fca6e50..eb349fd 100644
--- a/arch/arm/boot/dts/imx7ulp.dtsi
+++ b/arch/arm/boot/dts/imx7ulp.dtsi
@@ -286,6 +286,12 @@
status = "disabled";
};
 
+   memory-controller@40ab {
+   compatible = "fsl,imx7ulp-mmdc", "fsl,imx6q-mmdc";
+   reg = <0x40ab 0x1000>;
+   clocks = < IMX7ULP_CLK_MMDC>;
+   };
+
iomuxc1: pinctrl@40ac {
compatible = "fsl,imx7ulp-iomuxc1";
reg = <0x40ac 0x1000>;
-- 
2.7.4



Re: [GIT PULL] XArray updates for 5.1-rc1

2019-03-11 Thread Matthew Wilcox
On Mon, Mar 11, 2019 at 06:39:41PM -0700, Linus Torvalds wrote:
> On Mon, Mar 11, 2019 at 11:28 AM Matthew Wilcox  wrote:
> >
> >   git://git.infradead.org/users/willy/linux-dax.git xarray
> 
> You forgot to tag it, and I don't pull from external untrusted sites
> without signed tags..
> 
> Please? I know you can do it, because you've done it successfully in the 
> past...

Oops.  xarray-5.1-rc1 tag now created and pushed out.  Thanks.


[PATCH v2 0/5] drm: Fix fb changes for async updates

2019-03-11 Thread Helen Koike
Hello,

This series fixes the slow down in performance introduced by
"[PATCH v2] drm: Block fb changes for async plane updates" where async update
falls back to a sync update, causing igt failures of type:

"CRITICAL: completed 97 cursor updated in a period of 30 flips, we
expect to complete approximately 15360 updates, with the threshold set
at 7680"

Please read the commit message of "drm: don't block fb changes for async
plane updates" to understand how it works.

I tested on the rockchip, on i915 and on vc4 with igt plane_cursor_legacy and
kms_cursor_legacy and I didn't see any regressions.

I couldn't test on MSM and AMD because I don't have the hardware
I would appreciate if anyone could help me testing those.

v1 link: https://patchwork.kernel.org/cover/10837847/

Thanks!
Helen

Changes in v2:
- added reviewed-by tag
- update CC stable and Fixes tag
- Added reviewed-by tag
- updated CC stable and Fixes tag
- Change the order of the patch in the series, add this as the last one.
- Add documentation
- s/ballanced/balanced

Helen Koike (5):
  drm/rockchip: fix fb references in async update
  drm/amd: fix fb references in async update
  drm/msm: fix fb references in async update
  drm/vc4: fix fb references in async update
  drm: don't block fb changes for async plane updates

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  3 +-
 drivers/gpu/drm/drm_atomic_helper.c   | 20 -
 drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c|  4 ++
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c   | 42 +++
 drivers/gpu/drm/vc4/vc4_plane.c   |  2 +-
 include/drm/drm_modeset_helper_vtables.h  |  5 +++
 6 files changed, 45 insertions(+), 31 deletions(-)

-- 
2.20.1



[PATCH 17/30] perf script python: Add Python3 support to export-to-sqlite.py

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Tony Jones 

Support both Python2 and Python3 in the export-to-sqlite.py script

The use of 'from __future__' implies the minimum supported Python2 version
is now v2.6

Signed-off-by: Tony Jones 
Acked-by: Adrian Hunter 
Link: http://lkml.kernel.org/r/20190309000518.2438-4-to...@suse.de
Signed-off-by: Seeteena Thoufeek 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/scripts/python/export-to-sqlite.py | 23 +++
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-sqlite.py 
b/tools/perf/scripts/python/export-to-sqlite.py
index eb63e6c7107f..3da338243aed 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -10,6 +10,8 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
+from __future__ import print_function
+
 import os
 import sys
 import struct
@@ -60,11 +62,14 @@ perf_db_export_mode = True
 perf_db_export_calls = False
 perf_db_export_callchains = False
 
+def printerr(*args, **keyword_args):
+   print(*args, file=sys.stderr, **keyword_args)
+
 def usage():
-   print >> sys.stderr, "Usage is: export-to-sqlite.py  
[] [] []"
-   print >> sys.stderr, "where:columns 'all' or 'branches'"
-   print >> sys.stderr, "  calls   'calls' => create calls 
and call_paths table"
-   print >> sys.stderr, "  callchains  'callchains' => create 
call_paths table"
+   printerr("Usage is: export-to-sqlite.py  [] 
[] []");
+   printerr("where:columns 'all' or 'branches'");
+   printerr("  calls   'calls' => create calls and 
call_paths table");
+   printerr("  callchains  'callchains' => create 
call_paths table");
raise Exception("Too few arguments")
 
 if (len(sys.argv) < 2):
@@ -100,7 +105,7 @@ def do_query_(q):
return
raise Exception("Query failed: " + q.lastError().text())
 
-print datetime.datetime.today(), "Creating database..."
+print(datetime.datetime.today(), "Creating database ...")
 
 db_exists = False
 try:
@@ -378,7 +383,7 @@ if perf_db_export_calls:
call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, 
?, ?, ?, ?)")
 
 def trace_begin():
-   print datetime.datetime.today(), "Writing records..."
+   print(datetime.datetime.today(), "Writing records...")
do_query(query, 'BEGIN TRANSACTION')
# id == 0 means unknown.  It is easier to create records for them than 
replace the zeroes with NULLs
evsel_table(0, "unknown")
@@ -397,14 +402,14 @@ unhandled_count = 0
 def trace_end():
do_query(query, 'END TRANSACTION')
 
-   print datetime.datetime.today(), "Adding indexes"
+   print(datetime.datetime.today(), "Adding indexes")
if perf_db_export_calls:
do_query(query, 'CREATE INDEX pcpid_idx ON calls 
(parent_call_path_id)')
do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
 
if (unhandled_count):
-   print datetime.datetime.today(), "Warning: ", unhandled_count, 
" unhandled events"
-   print datetime.datetime.today(), "Done"
+   print(datetime.datetime.today(), "Warning: ", unhandled_count, 
" unhandled events")
+   print(datetime.datetime.today(), "Done")
 
 def trace_unhandled(event_name, context, event_fields_dict):
global unhandled_count
-- 
2.20.1



[PATCH] appletalk: Fix potential NULL pointer dereference in unregister_snap_client

2019-03-11 Thread Yue Haibing
From: YueHaibing 

register_snap_client may return NULL, all the callers
check it, but only print a warning. This will result in
NULL pointer dereference in unregister_snap_client and other
places.

It has always been used like this since v2.6

Reported-by: Dan Carpenter 
Signed-off-by: YueHaibing 
---
 include/linux/atalk.h |  2 +-
 net/appletalk/aarp.c  | 13 ++---
 net/appletalk/ddp.c   | 20 
 3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/include/linux/atalk.h b/include/linux/atalk.h
index 5a90f28..0e5265a 100644
--- a/include/linux/atalk.h
+++ b/include/linux/atalk.h
@@ -108,7 +108,7 @@ static __inline__ struct elapaarp *aarp_hdr(struct sk_buff 
*skb)
 #define AARP_RESOLVE_TIME  (10 * HZ)
 
 extern struct datalink_proto *ddp_dl, *aarp_dl;
-extern void aarp_proto_init(void);
+extern int aarp_proto_init(void);
 
 /* Inter module exports */
 
diff --git a/net/appletalk/aarp.c b/net/appletalk/aarp.c
index 49a16ce..d11372d 100644
--- a/net/appletalk/aarp.c
+++ b/net/appletalk/aarp.c
@@ -879,15 +879,22 @@ static struct notifier_block aarp_notifier = {
 
 static unsigned char aarp_snap_id[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
 
-void __init aarp_proto_init(void)
+int __init aarp_proto_init(void)
 {
+   int rc;
+
aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv);
-   if (!aarp_dl)
+   if (!aarp_dl) {
printk(KERN_CRIT "Unable to register AARP with SNAP.\n");
+   return -ENOMEM;
+   }
timer_setup(_timer, aarp_expire_timeout, 0);
aarp_timer.expires  = jiffies + sysctl_aarp_expiry_time;
add_timer(_timer);
-   register_netdevice_notifier(_notifier);
+   rc = register_netdevice_notifier(_notifier);
+   if (rc)
+   unregister_snap_client(aarp_dl);
+   return rc;
 }
 
 /* Remove the AARP entries associated with a device. */
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index 795fbc6..709d254 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -1904,9 +1904,6 @@ static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 
0x80, 0x9B };
 EXPORT_SYMBOL(atrtr_get_dev);
 EXPORT_SYMBOL(atalk_find_dev_addr);
 
-static const char atalk_err_snap[] __initconst =
-   KERN_CRIT "Unable to register DDP with SNAP.\n";
-
 /* Called by proto.c on kernel start up */
 static int __init atalk_init(void)
 {
@@ -1921,17 +1918,22 @@ static int __init atalk_init(void)
goto out_proto;
 
ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
-   if (!ddp_dl)
-   printk(atalk_err_snap);
+   if (!ddp_dl) {
+   pr_crit("Unable to register DDP with SNAP.\n");
+   goto out_sock;
+   }
 
dev_add_pack(_packet_type);
dev_add_pack(_packet_type);
 
rc = register_netdevice_notifier(_notifier);
if (rc)
-   goto out_sock;
+   goto out_snap;
+
+   rc = aarp_proto_init();
+   if (rc)
+   goto out_dev;
 
-   aarp_proto_init();
rc = atalk_proc_init();
if (rc)
goto out_aarp;
@@ -1945,11 +1947,13 @@ static int __init atalk_init(void)
atalk_proc_exit();
 out_aarp:
aarp_cleanup_module();
+out_dev:
unregister_netdevice_notifier(_notifier);
-out_sock:
+out_snap:
dev_remove_pack(_packet_type);
dev_remove_pack(_packet_type);
unregister_snap_client(ddp_dl);
+out_sock:
sock_unregister(PF_APPLETALK);
 out_proto:
proto_unregister(_proto);
-- 
2.7.0




[PATCH 28/30] perf script: Add array bound checking to list_scripts

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Don't overflow array when the scripts directory is too large, or the
script file name is too long.

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-11-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c  | 8 ++--
 tools/perf/builtin.h | 3 ++-
 tools/perf/ui/browsers/scripts.c | 3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index b695b20ffc8a..2f93d60c5a17 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2982,7 +2982,8 @@ static int check_ev_match(char *dir_name, char 
*scriptname,
  * will list all statically runnable scripts, select one, execute it and
  * show the output in a perf browser.
  */
-int find_scripts(char **scripts_array, char **scripts_path_array)
+int find_scripts(char **scripts_array, char **scripts_path_array, int num,
+int pathlen)
 {
struct dirent *script_dirent, *lang_dirent;
char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
@@ -3027,7 +3028,10 @@ int find_scripts(char **scripts_array, char 
**scripts_path_array)
/* Skip those real time scripts: xxxtop.p[yl] */
if (strstr(script_dirent->d_name, "top."))
continue;
-   sprintf(scripts_path_array[i], "%s/%s", lang_path,
+   if (i >= num)
+   break;
+   snprintf(scripts_path_array[i], pathlen, "%s/%s",
+   lang_path,
script_dirent->d_name);
temp = strchr(script_dirent->d_name, '.');
snprintf(scripts_array[i],
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 05745f3ce912..999fe9170122 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -40,5 +40,6 @@ int cmd_mem(int argc, const char **argv);
 int cmd_data(int argc, const char **argv);
 int cmd_ftrace(int argc, const char **argv);
 
-int find_scripts(char **scripts_array, char **scripts_path_array);
+int find_scripts(char **scripts_array, char **scripts_path_array, int num,
+int pathlen);
 #endif
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index cdba58447b85..96e5cd3b0eee 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -97,7 +97,8 @@ static int list_scripts(char *script_name, bool *custom,
paths[i] = names[i] + SCRIPT_NAMELEN;
}
 
-   num = find_scripts(names + max_std, paths + max_std);
+   num = find_scripts(names + max_std, paths + max_std, SCRIPT_MAX_NO - 
max_std,
+   SCRIPT_FULLPATH_LEN);
if (num < 0)
num = 0;
choice = ui__popup_menu(num + max_std, (char * const *)names);
-- 
2.20.1



[PATCH 04/30] perf time-utils: Add utility function to print time stamps in nanoseconds

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Add a utility function to print nanosecond timestamps.

Signed-off-by: Andi Kleen 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: http://lkml.kernel.org/r/20190305144758.12397-11-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/time-utils.c | 8 
 tools/perf/util/time-utils.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c
index 0f53baec660e..20663a460df3 100644
--- a/tools/perf/util/time-utils.c
+++ b/tools/perf/util/time-utils.c
@@ -453,6 +453,14 @@ int timestamp__scnprintf_usec(u64 timestamp, char *buf, 
size_t sz)
return scnprintf(buf, sz, "%"PRIu64".%06"PRIu64, sec, usec);
 }
 
+int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz)
+{
+   u64 sec  = timestamp / NSEC_PER_SEC,
+   nsec = timestamp % NSEC_PER_SEC;
+
+   return scnprintf(buf, sz, "%" PRIu64 ".%09" PRIu64, sec, nsec);
+}
+
 int fetch_current_timestamp(char *buf, size_t sz)
 {
struct timeval tv;
diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h
index b923de44e36f..72a42ea1d513 100644
--- a/tools/perf/util/time-utils.h
+++ b/tools/perf/util/time-utils.h
@@ -30,6 +30,7 @@ int perf_time__parse_for_ranges(const char *str, struct 
perf_session *session,
int *range_size, int *range_num);
 
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
+int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz);
 
 int fetch_current_timestamp(char *buf, size_t sz);
 
-- 
2.20.1



[PATCH 19/30] perf tools: Update x86's syscall_64.tbl, no change in tools/perf behaviour

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

To pick the changes in 7948450d4556 ("x86/x32: use time64 versions of
sigtimedwait and recvmmsg"), that doesn't cause any change in behaviour
in tools/perf/ as it deals just with the x32 entries.

This silences this tools/perf build warning:

  Warning: Kernel ABI header at 
'tools/perf/arch/x86/entry/syscalls/syscall_64.tbl' differs from latest version 
at 'arch/x86/entry/syscalls/syscall_64.tbl'
  diff -u tools/perf/arch/x86/entry/syscalls/syscall_64.tbl 
arch/x86/entry/syscalls/syscall_64.tbl

Cc: Adrian Hunter 
Cc: Arnd Bergmann 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-mqpvshayeqidlulx5qpio...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl 
b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
index f0b1709a5ffb..2ae92fddb6d5 100644
--- a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
@@ -343,6 +343,8 @@
 332common  statx   __x64_sys_statx
 333common  io_pgetevents   __x64_sys_io_pgetevents
 334common  rseq__x64_sys_rseq
+# don't use numbers 387 through 423, add new calls after the last
+# 'common' entry
 
 #
 # x32-specific system call numbers start at 512 to avoid cache impact
@@ -361,7 +363,7 @@
 520x32 execve  __x32_compat_sys_execve/ptregs
 521x32 ptrace  __x32_compat_sys_ptrace
 522x32 rt_sigpending   __x32_compat_sys_rt_sigpending
-523x32 rt_sigtimedwait __x32_compat_sys_rt_sigtimedwait
+523x32 rt_sigtimedwait __x32_compat_sys_rt_sigtimedwait_time64
 524x32 rt_sigqueueinfo __x32_compat_sys_rt_sigqueueinfo
 525x32 sigaltstack __x32_compat_sys_sigaltstack
 526x32 timer_create__x32_compat_sys_timer_create
@@ -375,7 +377,7 @@
 534x32 preadv  __x32_compat_sys_preadv64
 535x32 pwritev __x32_compat_sys_pwritev64
 536x32 rt_tgsigqueueinfo   __x32_compat_sys_rt_tgsigqueueinfo
-537x32 recvmmsg__x32_compat_sys_recvmmsg
+537x32 recvmmsg__x32_compat_sys_recvmmsg_time64
 538x32 sendmmsg__x32_compat_sys_sendmmsg
 539x32 process_vm_readv__x32_compat_sys_process_vm_readv
 540x32 process_vm_writev   __x32_compat_sys_process_vm_writev
-- 
2.20.1



[PATCH 21/30] tools headers uapi: Update linux/in.h copy

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

To get the changes in:

  4effd28c1245 ("bridge: join all-snoopers multicast address")

That do not generate any changes in tools/ use of this file.

Silences this tools/perf build warning:

  Warning: Kernel ABI header at 'tools/include/uapi/linux/in.h' differs from 
latest version at 'include/uapi/linux/in.h'
  diff -u tools/include/uapi/linux/in.h include/uapi/linux/in.h

Cc: Adrian Hunter 
Cc: David S. Miller 
Cc: Jiri Olsa 
Cc: Linus Lüssing 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-ifpl634035266ho6wxuqg...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/uapi/linux/in.h | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/include/uapi/linux/in.h b/tools/include/uapi/linux/in.h
index a55cb8b10165..e7ad9d350a28 100644
--- a/tools/include/uapi/linux/in.h
+++ b/tools/include/uapi/linux/in.h
@@ -292,10 +292,11 @@ struct sockaddr_in {
 #defineIN_LOOPBACK(a)  long int) (a)) & 0xff00) == 
0x7f00)
 
 /* Defines for Multicast INADDR */
-#define INADDR_UNSPEC_GROUP0xe000U /* 224.0.0.0   */
-#define INADDR_ALLHOSTS_GROUP  0xe001U /* 224.0.0.1   */
-#define INADDR_ALLRTRS_GROUP0xe002U/* 224.0.0.2 */
-#define INADDR_MAX_LOCAL_GROUP  0xe0ffU/* 224.0.0.255 */
+#define INADDR_UNSPEC_GROUP0xe000U /* 224.0.0.0   */
+#define INADDR_ALLHOSTS_GROUP  0xe001U /* 224.0.0.1   */
+#define INADDR_ALLRTRS_GROUP   0xe002U /* 224.0.0.2 */
+#define INADDR_ALLSNOOPERS_GROUP   0xe06aU /* 224.0.0.106 */
+#define INADDR_MAX_LOCAL_GROUP 0xe0ffU /* 224.0.0.255 */
 #endif
 
 /*  contains the htonl type stuff.. */
-- 
2.20.1



[PATCH 25/30] perf report: Support builtin perf script in scripts menu

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

The scripts menu traditionally only showed custom perf scripts.

Allow to run standard perf script with useful default options too.

- Normal perf script
- perf script with assembler (needs xed installed)
- perf script with source code output (needs debuginfo)
- perf script with custom arguments

Then we automatically select the right options to display the
information in the perf.data file.

For example with -b display branch contexts.

It's not easily possible to check for xed's existence in advance.  perf
script usually gives sensible error messages when it's not available.

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-7-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c |   2 +-
 tools/perf/ui/browsers/hists.c|  23 +++---
 tools/perf/ui/browsers/scripts.c  | 127 +++---
 tools/perf/util/hist.h|   8 +-
 4 files changed, 120 insertions(+), 40 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 35bdfd8b1e71..98d934a36d86 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -750,7 +750,7 @@ static int annotate_browser__run(struct annotate_browser 
*browser,
continue;
case 'r':
{
-   script_browse(NULL);
+   script_browse(NULL, NULL);
continue;
}
case 'k':
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index f98aeac607dd..fb4430f8982c 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2344,6 +2344,7 @@ struct popup_action {
struct thread   *thread;
struct map_symbol   ms;
int socket;
+   struct perf_evsel   *evsel;
 
int (*fn)(struct hist_browser *browser, struct popup_action *act);
 };
@@ -2566,7 +2567,7 @@ do_run_script(struct hist_browser *browser __maybe_unused,
n += snprintf(script_opt + n, len - n, " --time %s,%s", start, 
end);
}
 
-   script_browse(script_opt);
+   script_browse(script_opt, act->evsel);
free(script_opt);
return 0;
 }
@@ -2575,7 +2576,7 @@ static int
 add_script_opt_2(struct hist_browser *browser __maybe_unused,
   struct popup_action *act, char **optstr,
   struct thread *thread, struct symbol *sym,
-  const char *tstr)
+  struct perf_evsel *evsel, const char *tstr)
 {
 
if (thread) {
@@ -2593,6 +2594,7 @@ add_script_opt_2(struct hist_browser *browser 
__maybe_unused,
 
act->thread = thread;
act->ms.sym = sym;
+   act->evsel = evsel;
act->fn = do_run_script;
return 1;
 }
@@ -2600,12 +2602,13 @@ add_script_opt_2(struct hist_browser *browser 
__maybe_unused,
 static int
 add_script_opt(struct hist_browser *browser,
   struct popup_action *act, char **optstr,
-  struct thread *thread, struct symbol *sym)
+  struct thread *thread, struct symbol *sym,
+  struct perf_evsel *evsel)
 {
int n, j;
struct hist_entry *he;
 
-   n = add_script_opt_2(browser, act, optstr, thread, sym, "");
+   n = add_script_opt_2(browser, act, optstr, thread, sym, evsel, "");
 
he = hist_browser__selected_entry(browser);
if (sort_order && strstr(sort_order, "time")) {
@@ -2618,10 +2621,9 @@ add_script_opt(struct hist_browser *browser,
   sizeof tstr - j);
j += sprintf(tstr + j, "-");
timestamp__scnprintf_usec(he->time + symbol_conf.time_quantum,
- tstr + j,
- sizeof tstr - j);
+ tstr + j, sizeof tstr - j);
n += add_script_opt_2(browser, act, optstr, thread, sym,
- tstr);
+ evsel, tstr);
act->time = he->time;
}
return n;
@@ -3092,7 +3094,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
nr_options += add_script_opt(browser,
 
[nr_options],
 
[nr_options],
-thread, NULL);
+thread, NULL, 
evsel);
}
/*
 * Note that browser->selection != NULL
@@ -3107,11 +3109,12 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int 

[PATCH 27/30] perf tools: Add some new tips describing the new options

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-9-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/tips.txt | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/tools/perf/Documentation/tips.txt 
b/tools/perf/Documentation/tips.txt
index 849599f39c5e..869965d629ce 100644
--- a/tools/perf/Documentation/tips.txt
+++ b/tools/perf/Documentation/tips.txt
@@ -15,6 +15,7 @@ To see callchains in a more compact form: perf report -g 
folded
 Show individual samples with: perf script
 Limit to show entries above 5% only: perf report --percent-limit 5
 Profiling branch (mis)predictions with: perf record -b / perf report
+To show assembler sample contexts use perf record -b / perf script -F 
+brstackinsn --xed
 Treat branches as callchains: perf report --branch-history
 To count events in every 1000 msec: perf stat -I 1000
 Print event counts in CSV format with: perf stat -x,
@@ -34,3 +35,9 @@ Show current config key-value pairs: perf config --list
 Show user configuration overrides: perf config --user --list
 To add Node.js USDT(User-Level Statically Defined Tracing): perf buildid-cache 
--add `which node`
 To report cacheline events from previous recording: perf c2c report
+To browse sample contexts use perf report --sample 10 and select in context 
menu
+To separate samples by time use perf report --sort time,overhead,sym
+To set sample time separation other than 100ms with --sort time use 
--time-quantum
+Add -I to perf report to sample register values visible in perf report context.
+To show IPC for sampling periods use perf record -e '{cycles,instructions}:S' 
and then browse context
+To show context switches in perf report sample context add --switch-events to 
perf record.
-- 
2.20.1



[PATCH 29/30] perf ui browser: Fix ui popup argv browser for many entries

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Fix the argv ui browser code to correctly display more entries than fit
on the screen without crashing. The problem was some type confusion with
pointer types in the ->seek function. Do the argv arithmetic correctly
with char ** pointers. Also add some asserts to find overruns and limit
the display function correctly.

Then finally remove a workaround for this in the res sample browser.

Committer testing:

1) Resize the x terminal to have just some 5 lines

2) Use 'perf report --samples 1' to activate the sample browser options
   in the menu

3) Press ENTER, this will cause the crash:

  # perf report --samples 1
  perf: Segmentation fault
   backtrace 
  perf[0x5a514a]
  /lib64/libc.so.6(+0x385bf)[0x7f27281b55bf]
  /lib64/libc.so.6(+0x161a67)[0x7f27282dea67]
  /lib64/libslang.so.2(SLsmg_write_wrapped_string+0x82)[0x7f272874a0b2]
  perf(ui_browser__argv_refresh+0x77)[0x5939a7]
  perf[0x5924cc]
  perf(ui_browser__run+0x39)[0x593449]
  perf(ui__popup_menu+0x83)[0x5a5263]
  perf[0x59f421]
  perf(perf_evlist__tui_browse_hists+0x3a0)[0x5a3780]
  perf(cmd_report+0x2746)[0x447136]
  perf[0x4a95fe]
  perf(main+0x61c)[0x42dc6c]
  /lib64/libc.so.6(__libc_start_main+0xf2)[0x7f27281a1412]
  perf(_start+0x2d)[0x42de9d]
  #

After applying this patch no crash takes place in such situation.

Signed-off-by: Andi Kleen 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-12-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browser.c | 10 +++---
 tools/perf/ui/browsers/res_sample.c |  3 ---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 4f75561424ed..4ad37d8c7d6a 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -611,14 +611,16 @@ void ui_browser__argv_seek(struct ui_browser *browser, 
off_t offset, int whence)
browser->top = browser->entries;
break;
case SEEK_CUR:
-   browser->top = browser->top + browser->top_idx + offset;
+   browser->top = (char **)browser->top + offset;
break;
case SEEK_END:
-   browser->top = browser->top + browser->nr_entries - 1 + offset;
+   browser->top = (char **)browser->entries + browser->nr_entries 
- 1 + offset;
break;
default:
return;
}
+   assert((char **)browser->top < (char **)browser->entries + 
browser->nr_entries);
+   assert((char **)browser->top >= (char **)browser->entries);
 }
 
 unsigned int ui_browser__argv_refresh(struct ui_browser *browser)
@@ -630,7 +632,9 @@ unsigned int ui_browser__argv_refresh(struct ui_browser 
*browser)
browser->top = browser->entries;
 
pos = (char **)browser->top;
-   while (idx < browser->nr_entries) {
+   while (idx < browser->nr_entries &&
+  row < (unsigned)SLtt_Screen_Rows - 1) {
+   assert(pos < (char **)browser->entries + browser->nr_entries);
if (!browser->filter || !browser->filter(browser, *pos)) {
ui_browser__gotorc(browser, row, 0);
browser->write(browser, pos, row);
diff --git a/tools/perf/ui/browsers/res_sample.c 
b/tools/perf/ui/browsers/res_sample.c
index 884ef2a92c15..c0dd73176d42 100644
--- a/tools/perf/ui/browsers/res_sample.c
+++ b/tools/perf/ui/browsers/res_sample.c
@@ -36,9 +36,6 @@ int res_sample_browse(struct res_sample *res_samples, int 
num_res,
struct res_sample *r;
char extra_format[256];
 
-   /* For now since ui__popup_menu doesn't like lists that don't fit */
-   num_res = max(min(SLtt_Screen_Rows - 4, num_res), 0);
-
names = calloc(num_res, sizeof(char *));
if (!names)
return -1;
-- 
2.20.1



[PATCH 22/30] perf script: Filter COMM/FORK/.. events by CPU

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

The --cpu option only filtered samples. Filter other perf events, such
as COMM, FORK, SWITCH by the CPU too.

Reported-by: Jiri Olsa 
Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-2-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c | 71 -
 1 file changed, 47 insertions(+), 24 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 111787e83784..b695b20ffc8a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1933,6 +1933,13 @@ static int cleanup_scripting(void)
return scripting_ops ? scripting_ops->stop_script() : 0;
 }
 
+static bool filter_cpu(struct perf_sample *sample)
+{
+   if (cpu_list)
+   return !test_bit(sample->cpu, cpu_bitmap);
+   return false;
+}
+
 static int process_sample_event(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
@@ -1967,7 +1974,7 @@ static int process_sample_event(struct perf_tool *tool,
if (al.filtered)
goto out_put;
 
-   if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
+   if (filter_cpu(sample))
goto out_put;
 
if (scripting_ops)
@@ -2052,9 +2059,11 @@ static int process_comm_event(struct perf_tool *tool,
sample->tid = event->comm.tid;
sample->pid = event->comm.pid;
}
-   perf_sample__fprintf_start(sample, thread, evsel,
+   if (!filter_cpu(sample)) {
+   perf_sample__fprintf_start(sample, thread, evsel,
   PERF_RECORD_COMM, stdout);
-   perf_event__fprintf(event, stdout);
+   perf_event__fprintf(event, stdout);
+   }
ret = 0;
 out:
thread__put(thread);
@@ -2088,9 +2097,11 @@ static int process_namespaces_event(struct perf_tool 
*tool,
sample->tid = event->namespaces.tid;
sample->pid = event->namespaces.pid;
}
-   perf_sample__fprintf_start(sample, thread, evsel,
-  PERF_RECORD_NAMESPACES, stdout);
-   perf_event__fprintf(event, stdout);
+   if (!filter_cpu(sample)) {
+   perf_sample__fprintf_start(sample, thread, evsel,
+  PERF_RECORD_NAMESPACES, stdout);
+   perf_event__fprintf(event, stdout);
+   }
ret = 0;
 out:
thread__put(thread);
@@ -2122,9 +2133,11 @@ static int process_fork_event(struct perf_tool *tool,
sample->tid = event->fork.tid;
sample->pid = event->fork.pid;
}
-   perf_sample__fprintf_start(sample, thread, evsel,
-  PERF_RECORD_FORK, stdout);
-   perf_event__fprintf(event, stdout);
+   if (!filter_cpu(sample)) {
+   perf_sample__fprintf_start(sample, thread, evsel,
+  PERF_RECORD_FORK, stdout);
+   perf_event__fprintf(event, stdout);
+   }
thread__put(thread);
 
return 0;
@@ -2152,9 +2165,11 @@ static int process_exit_event(struct perf_tool *tool,
sample->tid = event->fork.tid;
sample->pid = event->fork.pid;
}
-   perf_sample__fprintf_start(sample, thread, evsel,
-  PERF_RECORD_EXIT, stdout);
-   perf_event__fprintf(event, stdout);
+   if (!filter_cpu(sample)) {
+   perf_sample__fprintf_start(sample, thread, evsel,
+  PERF_RECORD_EXIT, stdout);
+   perf_event__fprintf(event, stdout);
+   }
 
if (perf_event__process_exit(tool, event, sample, machine) < 0)
err = -1;
@@ -2188,9 +2203,11 @@ static int process_mmap_event(struct perf_tool *tool,
sample->tid = event->mmap.tid;
sample->pid = event->mmap.pid;
}
-   perf_sample__fprintf_start(sample, thread, evsel,
-  PERF_RECORD_MMAP, stdout);
-   perf_event__fprintf(event, stdout);
+   if (!filter_cpu(sample)) {
+   perf_sample__fprintf_start(sample, thread, evsel,
+  PERF_RECORD_MMAP, stdout);
+   perf_event__fprintf(event, stdout);
+   }
thread__put(thread);
return 0;
 }
@@ -2220,9 +2237,11 @@ static int process_mmap2_event(struct perf_tool *tool,
sample->tid = event->mmap2.tid;
sample->pid = event->mmap2.pid;
}
-   perf_sample__fprintf_start(sample, thread, evsel,
-  PERF_RECORD_MMAP2, stdout);
-   perf_event__fprintf(event, stdout);
+   if (!filter_cpu(sample)) {
+   perf_sample__fprintf_start(sample, thread, evsel,
+

[PATCH 30/30] perf tools report: Add custom scripts to script menu

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Add a way to define custom scripts through ~/.perfconfig, which are then
added to the scripts menu. The scripts get the same arguments as 'perf
script', in particular -i, --cpu, --tid.

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-10-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-config.txt |  8 
 tools/perf/ui/browsers/scripts.c | 20 
 2 files changed, 28 insertions(+)

diff --git a/tools/perf/Documentation/perf-config.txt 
b/tools/perf/Documentation/perf-config.txt
index 2d0fb7613134..95054a8176a2 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -590,6 +590,14 @@ samples.*::
Define how many ns worth of time to show
around samples in perf report sample context browser.
 
+scripts.*::
+
+   Any option defines a script that is added to the scripts menu
+   in the interactive perf browser and whose output is displayed.
+   The name of the option is the name, the value is a script command line.
+   The script gets the same options passed as a full perf script,
+   in particular -i perfdata file, --cpu, --tid
+
 SEE ALSO
 
 linkperf:perf[1]
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index 96e5cd3b0eee..27cf3ab88d13 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -6,6 +6,7 @@
 #include "../../util/symbol.h"
 #include "../browser.h"
 #include "../libslang.h"
+#include "config.h"
 
 #define SCRIPT_NAMELEN 128
 #define SCRIPT_MAX_NO  64
@@ -53,6 +54,24 @@ static int add_script_option(const char *name, const char 
*opt,
return 0;
 }
 
+static int scripts_config(const char *var, const char *value, void *data)
+{
+   struct script_config *c = data;
+
+   if (!strstarts(var, "scripts."))
+   return -1;
+   if (c->index >= SCRIPT_MAX_NO)
+   return -1;
+   c->names[c->index] = strdup(var + 7);
+   if (!c->names[c->index])
+   return -1;
+   if (asprintf(>paths[c->index], "%s %s", value,
+c->extra_format) < 0)
+   return -1;
+   c->index++;
+   return 0;
+}
+
 /*
  * When success, will copy the full path of the selected script
  * into  the buffer pointed by script_name, and return 0.
@@ -87,6 +106,7 @@ static int list_scripts(char *script_name, bool *custom,
  );
add_script_option("Show individual samples with source", "-F 
+srcline,+srccode",
  );
+   perf_config(scripts_config, );
custom_perf = scriptc.index;
add_script_option("Show samples with custom perf script arguments", "", 
);
i = scriptc.index;
-- 
2.20.1



[PATCH 24/30] perf report: Support running scripts for current time range

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

When using the time sort key, add new context menus to run scripts for
only the currently selected time range. Compute the correct range for
the selection add pass it as the --time option to perf script.

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-6-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 83 +-
 1 file changed, 72 insertions(+), 11 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index aef800d97ea1..f98aeac607dd 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "../../util/callchain.h"
 #include "../../util/evsel.h"
@@ -30,6 +31,7 @@
 #include "srcline.h"
 #include "string2.h"
 #include "units.h"
+#include "time-utils.h"
 
 #include "sane_ctype.h"
 
@@ -2338,6 +2340,7 @@ static int switch_data_file(void)
 }
 
 struct popup_action {
+   unsigned long   time;
struct thread   *thread;
struct map_symbol   ms;
int socket;
@@ -2527,36 +2530,64 @@ static int
 do_run_script(struct hist_browser *browser __maybe_unused,
  struct popup_action *act)
 {
-   char script_opt[64];
-   memset(script_opt, 0, sizeof(script_opt));
+   char *script_opt;
+   int len;
+   int n = 0;
+
+   len = 100;
+   if (act->thread)
+   len += strlen(thread__comm_str(act->thread));
+   else if (act->ms.sym)
+   len += strlen(act->ms.sym->name);
+   script_opt = malloc(len);
+   if (!script_opt)
+   return -1;
 
+   script_opt[0] = 0;
if (act->thread) {
-   scnprintf(script_opt, sizeof(script_opt), " -c %s ",
+   n = scnprintf(script_opt, len, " -c %s ",
  thread__comm_str(act->thread));
} else if (act->ms.sym) {
-   scnprintf(script_opt, sizeof(script_opt), " -S %s ",
+   n = scnprintf(script_opt, len, " -S %s ",
  act->ms.sym->name);
}
 
+   if (act->time) {
+   char start[32], end[32];
+   unsigned long starttime = act->time;
+   unsigned long endtime = act->time + symbol_conf.time_quantum;
+
+   if (starttime == endtime) { /* Display 1ms as fallback */
+   starttime -= 1*NSEC_PER_MSEC;
+   endtime += 1*NSEC_PER_MSEC;
+   }
+   timestamp__scnprintf_usec(starttime, start, sizeof start);
+   timestamp__scnprintf_usec(endtime, end, sizeof end);
+   n += snprintf(script_opt + n, len - n, " --time %s,%s", start, 
end);
+   }
+
script_browse(script_opt);
+   free(script_opt);
return 0;
 }
 
 static int
-add_script_opt(struct hist_browser *browser __maybe_unused,
+add_script_opt_2(struct hist_browser *browser __maybe_unused,
   struct popup_action *act, char **optstr,
-  struct thread *thread, struct symbol *sym)
+  struct thread *thread, struct symbol *sym,
+  const char *tstr)
 {
+
if (thread) {
-   if (asprintf(optstr, "Run scripts for samples of thread [%s]",
-thread__comm_str(thread)) < 0)
+   if (asprintf(optstr, "Run scripts for samples of thread [%s]%s",
+thread__comm_str(thread), tstr) < 0)
return 0;
} else if (sym) {
-   if (asprintf(optstr, "Run scripts for samples of symbol [%s]",
-sym->name) < 0)
+   if (asprintf(optstr, "Run scripts for samples of symbol [%s]%s",
+sym->name, tstr) < 0)
return 0;
} else {
-   if (asprintf(optstr, "Run scripts for all samples") < 0)
+   if (asprintf(optstr, "Run scripts for all samples%s", tstr) < 0)
return 0;
}
 
@@ -2566,6 +2597,36 @@ add_script_opt(struct hist_browser *browser 
__maybe_unused,
return 1;
 }
 
+static int
+add_script_opt(struct hist_browser *browser,
+  struct popup_action *act, char **optstr,
+  struct thread *thread, struct symbol *sym)
+{
+   int n, j;
+   struct hist_entry *he;
+
+   n = add_script_opt_2(browser, act, optstr, thread, sym, "");
+
+   he = hist_browser__selected_entry(browser);
+   if (sort_order && strstr(sort_order, "time")) {
+   char tstr[128];
+
+   optstr++;
+   act++;
+   j = sprintf(tstr, " in ");
+   j += timestamp__scnprintf_usec(he->time, tstr + j,
+  sizeof tstr - j);
+   j += sprintf(tstr + j, "-");
+   

[PATCH 23/30] perf report: Support time sort key

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Add a time sort key to perf report to display samples for different time
quantums separately. This allows easier analysis of workloads that
change over time, and also will allow looking at the context of samples.

% perf record ...
% perf report --sort time,overhead,symbol --time-quantum 1ms --stdio
...
 0.67%  277061.87300  [.] _dl_start
 0.50%  277061.87300  [.] f1
 0.50%  277061.87300  [.] f2
 0.33%  277061.87300  [.] main
 0.29%  277061.87300  [.] _dl_lookup_symbol_x
 0.29%  277061.87300  [.] dl_main
 0.29%  277061.87300  [.] do_lookup_x
 0.17%  277061.87300  [.] _dl_debug_initialize
 0.17%  277061.87300  [.] _dl_init_paths
 0.08%  277061.87300  [.] check_match
 0.04%  277061.87300  [.] _dl_count_modids
 1.33%  277061.87400  [.] f1
 1.33%  277061.87400  [.] f2
 1.33%  277061.87400  [.] main
 1.17%  277061.87500  [.] main
 1.08%  277061.87500  [.] f1
 1.08%  277061.87500  [.] f2
 1.00%  277061.87600  [.] main
 0.83%  277061.87600  [.] f1
 0.83%  277061.87600  [.] f2
 1.00%  277061.87700  [.] main

Committer notes:

Rename 'time' argument to hist_time() to htime to overcome this in older
distros:

  cc1: warnings being treated as errors
  util/hist.c: In function 'hist_time':
  util/hist.c:251: error: declaration of 'time' shadows a global declaration
  /usr/include/time.h:186: error: shadowed declaration is here

Signed-off-by: Andi Kleen 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311144502.15423-4-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-report.txt |  2 ++
 tools/perf/util/hist.c   | 11 +++
 tools/perf/util/hist.h   |  1 +
 tools/perf/util/sort.c   | 39 
 tools/perf/util/sort.h   |  2 ++
 5 files changed, 55 insertions(+)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index 9ec1702bccdd..546d87221ad8 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -105,6 +105,8 @@ OPTIONS
guest machine
- sample: Number of sample
- period: Raw number of event count of sample
+   - time: Separate the samples by time stamp with the resolution 
specified by
+   --time-quantum (default 100ms). Specify with overhead and before it.
 
By default, comm, dso and symbol keys are used.
(i.e. --sort comm,dso,symbol)
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index f9eb95bf3938..34c0f00c68d1 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static bool hists__filter_entry_by_dso(struct hists *hists,
   struct hist_entry *he);
@@ -192,6 +193,7 @@ void hists__calc_col_len(struct hists *hists, struct 
hist_entry *h)
hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3);
hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12);
hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12);
+   hists__new_col_len(hists, HISTC_TIME, 12);
 
if (h->srcline) {
len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header));
@@ -246,6 +248,14 @@ static void he_stat__add_cpumode_period(struct he_stat 
*he_stat,
}
 }
 
+static long hist_time(unsigned long htime)
+{
+   unsigned long time_quantum = symbol_conf.time_quantum;
+   if (time_quantum)
+   return (htime / time_quantum) * time_quantum;
+   return htime;
+}
+
 static void he_stat__add_period(struct he_stat *he_stat, u64 period,
u64 weight)
 {
@@ -635,6 +645,7 @@ __hists__add_entry(struct hists *hists,
.raw_data = sample->raw_data,
.raw_size = sample->raw_size,
.ops = ops,
+   .time = hist_time(sample->time),
}, *he = hists__findnew_entry(hists, , al, sample_self);
 
if (!hists->has_callchains && he && he->callchain_size != 0)
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 4af27fbab24f..6279eca56409 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -31,6 +31,7 @@ enum hist_filter {
 
 enum hist_column {
HISTC_SYMBOL,
+   HISTC_TIME,
HISTC_DSO,
HISTC_THREAD,
HISTC_COMM,
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index d2299e912e59..bdd30cab51cb 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -3,6 +3,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "sort.h"
 #include "hist.h"
 #include "comm.h"
@@ -15,6 +16,7 @@
 #include 
 #include "mem-events.h"
 #include "annotate.h"
+#include "time-utils.h"
 #include 
 
 regex_tparent_regex;
@@ -654,6 +656,42 @@ struct sort_entry sort_socket = {
.se_width_idx   = HISTC_SOCKET,
 };
 
+/* --sort time */

[PATCH 26/30] perf report: Implement browsing of individual samples

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Now 'perf report' can show whole time periods with 'perf script', but
the user still has to find individual samples of interest manually.

It would be expensive and complicated to search for the right samples in
the whole perf file. Typically users only need to look at a small number
of samples for useful analysis.

Also the full scripts tend to show samples of all CPUs and all threads
mixed up, which can be very confusing on larger systems.

Add a new --samples option to save a small random number of samples per
hist entry.

Use a reservoir sample technique to select a representatve number of
samples.

Then allow browsing the samples using 'perf script' as part of the hist
entry context menu. This automatically adds the right filters, so only
the thread or cpu of the sample is displayed. Then we use less' search
functionality to directly jump the to the time stamp of the selected
sample.

It uses different menus for assembler and source display.  Assembler
needs xed installed and source needs debuginfo.

Currently it only supports as many samples as fit on the screen due to
some limitations in the slang ui code.

Signed-off-by: Andi Kleen 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190311174605.ga29...@tassilo.jf.intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-config.txt |  6 ++
 tools/perf/Documentation/perf-report.txt |  4 +
 tools/perf/builtin-report.c  |  2 +
 tools/perf/ui/browsers/Build |  1 +
 tools/perf/ui/browsers/hists.c   | 47 
 tools/perf/ui/browsers/res_sample.c  | 94 
 tools/perf/ui/browsers/scripts.c |  2 +-
 tools/perf/util/hist.c   | 39 ++
 tools/perf/util/hist.h   | 22 ++
 tools/perf/util/sort.h   |  8 ++
 tools/perf/util/symbol.c |  1 +
 tools/perf/util/symbol_conf.h|  1 +
 12 files changed, 226 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/ui/browsers/res_sample.c

diff --git a/tools/perf/Documentation/perf-config.txt 
b/tools/perf/Documentation/perf-config.txt
index 86f3dcc15f83..2d0fb7613134 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -584,6 +584,12 @@ llvm.*::
llvm.opts::
Options passed to llc.
 
+samples.*::
+
+   samples.context::
+   Define how many ns worth of time to show
+   around samples in perf report sample context browser.
+
 SEE ALSO
 
 linkperf:perf[1]
diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index 546d87221ad8..f441baa794ce 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -461,6 +461,10 @@ include::itrace.txt[]
 --socket-filter::
Only report the samples on the processor socket that match with this 
filter
 
+--samples=N::
+   Save N individual samples for each histogram entry to show context in 
perf
+   report tui browser.
+
 --raw-trace::
When displaying traceevent output, do not use print fmt or plugins.
 
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 05c8dd41106c..1921aaa9cece 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1159,6 +1159,8 @@ int cmd_report(int argc, const char **argv)
OPT_BOOLEAN(0, "demangle-kernel", _conf.demangle_kernel,
"Enable kernel symbol demangling"),
OPT_BOOLEAN(0, "mem-mode", _mode, "mem access profile"),
+   OPT_INTEGER(0, "samples", _conf.res_sample,
+   "Number of samples to save per histogram entry for 
individual browsing"),
OPT_CALLBACK(0, "percent-limit", , "percent",
 "Don't show entries under that percent", 
parse_percent_limit),
OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
diff --git a/tools/perf/ui/browsers/Build b/tools/perf/ui/browsers/Build
index 8fee56b46502..fdf86f7981ca 100644
--- a/tools/perf/ui/browsers/Build
+++ b/tools/perf/ui/browsers/Build
@@ -3,6 +3,7 @@ perf-y += hists.o
 perf-y += map.o
 perf-y += scripts.o
 perf-y += header.o
+perf-y += res_sample.o
 
 CFLAGS_annotate.o += -DENABLE_SLFUTURE_CONST
 CFLAGS_hists.o+= -DENABLE_SLFUTURE_CONST
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fb4430f8982c..3421ecbdd3f0 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1226,6 +1226,8 @@ void hist_browser__init_hpp(void)
hist_browser__hpp_color_overhead_guest_us;
perf_hpp__format[PERF_HPP__OVERHEAD_ACC].color =
hist_browser__hpp_color_overhead_acc;
+
+   res_sample_init();
 }
 
 static int hist_browser__show_entry(struct hist_browser *browser,
@@ -2345,6 +2347,7 @@ struct 

WARN ON at kernel/sched/deadline.c task_non_contending

2019-03-11 Thread chengjian (D)

Hi.

When looking to test SCHED_DEADLINE syzkaller report an warn in
task_non_contending(). I tested the mainline kernel with the C program
and captured the same call trace.

[The previous message contains some strings in other formats,

making the mail less readable. So I resend it. SORRY.]


[  948.126369] WARNING: CPU: 4 PID: 17089 at kernel/sched/deadline.c:255 
task_non_contending+0xae0/0x1950

[  948.130198] Kernel panic - not syncing: panic_on_warn set ...
[  948.130198]
[  948.134221] CPU: 4 PID: 17089 Comm: syz-executor.1 Not tainted 
4.19.27 #2
[  948.139072] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), 
BIOS 1.10.2-1ubuntu1 04/01/2014

[  948.141603] Call Trace:
[  948.142277]  dump_stack+0xca/0x13e
[  948.164636]  panic+0x1f7/0x543
[  948.168704]  ? refcount_error_report+0x29d/0x29d
[  948.172438]  ? __warn+0x1d1/0x210
[  948.183359]  ? task_non_contending+0xae0/0x1950
[  948.191747]  __warn+0x1ec/0x210
[  948.196276]  ? task_non_contending+0xae0/0x1950
[  948.202476]  report_bug+0x1ee/0x2b0
[  948.204622]  fixup_bug.part.7+0x37/0x80
[  948.206879]  do_error_trap+0x22c/0x290
[  948.211340]  ? math_error+0x2f0/0x2f0
[  948.217033]  ? trace_hardirqs_off_caller+0x40/0x190
[  948.222477]  ? trace_hardirqs_off_thunk+0x1a/0x1c
[  948.229877]  invalid_op+0x14/0x20
[  948.238317] RIP: 0010:task_non_contending+0xae0/0x1950
[  948.253825] Code: 6d 29 83 48 89 4c 24 20 48 89 54 24 10 c6 05 d0 89 
5a 03 01 e8 11 ea ee ff 0f 0b 48 8b 4c 24 20 48 8b 54 24 10 e9 bb f7 ff 
ff <0f> 0b e9 1d f6 ff ff e8 d4 a7 09 00 85 c0 0f 85 74 f8 ff ff 48 c7

[  948.272329] RSP: 0018:8883d443f8c0 EFLAGS: 00010002
[  948.293045] RAX: 0001 RBX: 8883d3572468 RCX: 
813a6571
[  948.300323] RDX: 08ab RSI: c900030e4000 RDI: 
8883e2fe6278
[  948.305278] RBP: 8883e2f0 R08: ed1078ea3ab2 R09: 
ed1078ea3ab2
[  948.316441] R10: 0001 R11: ed1078ea3ab1 R12: 
0002c680
[  948.320257] R13: 8883d357217c R14: 0001 R15: 
8883d3572140

[  948.324500]  ? hrtimer_active+0x171/0x1f0
[  948.327421]  ? dequeue_task_dl+0x38/0x970
[  948.330572]  __schedule+0x94b/0x1a80
[  948.333578]  ? __sched_text_start+0x8/0x8
[  948.336141]  ? lock_downgrade+0x5e0/0x5e0
[  948.338111]  ? plist_add+0x23e/0x480
[  948.339706]  schedule+0x7c/0x1a0
[  948.341395]  futex_wait_queue_me+0x319/0x600
[  948.343329]  ? get_futex_key_refs+0xd0/0xd0
[  948.345037]  ? lock_downgrade+0x5e0/0x5e0
[  948.347206]  ? get_futex_key_refs+0xa4/0xd0
[  948.353007]  futex_wait+0x1e7/0x590
[  948.355328]  ? futex_wait_setup+0x2b0/0x2b0
[  948.360578]  ? __lock_acquire+0x60c/0x3b70
[  948.369186]  ? __save_stack_trace+0x92/0x100
[  948.374344]  ? hash_futex+0x15/0x210
[  948.376832]  ? drop_futex_key_refs+0x3c/0xd0
[  948.378591]  ? futex_wake+0x14e/0x450
[  948.381609]  do_futex+0x5c9/0x15e0
[  948.384567]  ? perf_syscall_enter+0xb1/0xc80
[  948.390307]  ? exit_robust_list+0x240/0x240
[  948.393566]  ? ftrace_syscall_exit+0x5c0/0x5c0
[  948.396369]  ? lock_downgrade+0x5e0/0x5e0
[  948.401748]  ? __might_fault+0x17c/0x1c0
[  948.404171]  __x64_sys_futex+0x296/0x380
[  948.406472]  ? __ia32_sys_futex+0x370/0x370
[  948.440630]  ? trace_hardirqs_on_thunk+0x1a/0x1c
[  948.441774]  ? trace_hardirqs_off_caller+0x40/0x190
[  948.442770]  ? do_syscall_64+0x3b/0x580
[  948.486728]  do_syscall_64+0xc8/0x580
[  948.489138]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[  948.492072] RIP: 0033:0x462eb9
[  948.492788] Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 
48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 
05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
[  948.532016] RSP: 002b:7f7ac8a67cd8 EFLAGS: 0246 ORIG_RAX: 
00ca
[  948.536811] RAX: ffda RBX: 0073bf08 RCX: 
00462eb9
[  948.542138] RDX:  RSI: 0080 RDI: 
0073bf08
[  948.548077] RBP: 0073bf00 R08:  R09: 

[  948.562535] R10:  R11: 0246 R12: 
0073bf0c
[  948.569184] R13:  R14: 0073bf00 R15: 
7fff106d8c10




WARNING at :

```cpp
static void task_non_contending(struct task_struct *p){
    // ..
    WARN_ON(hrtimer_active(_se->inactive_timer));
    WARN_ON(dl_se->dl_non_contending);
}
```

I have debug for it and found that hrtimer_try_to_cancel FAILED(return 
-1) in
migrate_task_rq_dl() because the timer handler `inactive_task_timer()` 
is running
at that time. so when the task  blocks later, theinactive_timer is still 
active

indequeue_task_dl().


```cpp
static void migrate_task_rq_dl(struct task_struct *p, int new_cpu 
__maybe_unused){

    /*
 * If the timer handler is currently running and the
     * timer cannot be cancelled, inactive_task_timer()
 * will see that dl_not_contending is not set, and
 * will not touch the rq's active utilization,
 * so we are still 

[PATCH 18/30] perf script python: Add printdate function to SQL exporters

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Tony Jones 

Introduce a printdate function to eliminate the repetitive use of
datetime.datetime.today() in the SQL exporting scripts.

Signed-off-by: Tony Jones 
Acked-by: Adrian Hunter 
Link: http://lkml.kernel.org/r/20190309000518.2438-5-to...@suse.de
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../scripts/python/export-to-postgresql.py| 19 +++
 tools/perf/scripts/python/export-to-sqlite.py | 13 -
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 00ab972a2eba..c3eae1d77d36 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -251,6 +251,9 @@ perf_db_export_callchains = False
 def printerr(*args, **kw_args):
print(*args, file=sys.stderr, **kw_args)
 
+def printdate(*args, **kw_args):
+print(datetime.datetime.today(), *args, sep=' ', **kw_args)
+
 def usage():
printerr("Usage is: export-to-postgresql.py  [] 
[] []")
printerr("where:columns 'all' or 'branches'")
@@ -289,7 +292,7 @@ def do_query(q, s):
return
raise Exception("Query failed: " + q.lastError().text())
 
-print(datetime.datetime.today(), "Creating database...")
+printdate("Creating database...")
 
 db = QSqlDatabase.addDatabase('QPSQL')
 query = QSqlQuery(db)
@@ -582,7 +585,7 @@ if perf_db_export_calls:
call_file   = open_output_file("call_table.bin")
 
 def trace_begin():
-   print(datetime.datetime.today(), "Writing to intermediate files...")
+   printdate("Writing to intermediate files...")
# id == 0 means unknown.  It is easier to create records for them than 
replace the zeroes with NULLs
evsel_table(0, "unknown")
machine_table(0, 0, "unknown")
@@ -598,7 +601,7 @@ def trace_begin():
 unhandled_count = 0
 
 def trace_end():
-   print(datetime.datetime.today(), "Copying to database...")
+   printdate("Copying to database...")
copy_output_file(evsel_file,"selected_events")
copy_output_file(machine_file,  "machines")
copy_output_file(thread_file,   "threads")
@@ -613,7 +616,7 @@ def trace_end():
if perf_db_export_calls:
copy_output_file(call_file, "calls")
 
-   print(datetime.datetime.today(), "Removing intermediate files...")
+   printdate("Removing intermediate files...")
remove_output_file(evsel_file)
remove_output_file(machine_file)
remove_output_file(thread_file)
@@ -628,7 +631,7 @@ def trace_end():
if perf_db_export_calls:
remove_output_file(call_file)
os.rmdir(output_dir_name)
-   print(datetime.datetime.today(), "Adding primary keys")
+   printdate("Adding primary keys")
do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
do_query(query, 'ALTER TABLE machinesADD PRIMARY KEY (id)')
do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)')
@@ -643,7 +646,7 @@ def trace_end():
if perf_db_export_calls:
do_query(query, 'ALTER TABLE calls   ADD PRIMARY KEY 
(id)')
 
-   print(datetime.datetime.today(), "Adding foreign keys")
+   printdate("Adding foreign keys")
do_query(query, 'ALTER TABLE threads '
'ADD CONSTRAINT machinefk  FOREIGN KEY 
(machine_id)   REFERENCES machines   (id),'
'ADD CONSTRAINT processfk  FOREIGN KEY 
(process_id)   REFERENCES threads(id)')
@@ -679,8 +682,8 @@ def trace_end():
do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
 
if (unhandled_count):
-   print(datetime.datetime.today(), "Warning: ", unhandled_count, 
" unhandled events")
-   print(datetime.datetime.today(), "Done")
+   printdate("Warning: ", unhandled_count, " unhandled events")
+   printdate("Done")
 
 def trace_unhandled(event_name, context, event_fields_dict):
global unhandled_count
diff --git a/tools/perf/scripts/python/export-to-sqlite.py 
b/tools/perf/scripts/python/export-to-sqlite.py
index 3da338243aed..3b71902a5a21 100644
--- a/tools/perf/scripts/python/export-to-sqlite.py
+++ b/tools/perf/scripts/python/export-to-sqlite.py
@@ -65,6 +65,9 @@ perf_db_export_callchains = False
 def printerr(*args, **keyword_args):
print(*args, file=sys.stderr, **keyword_args)
 
+def printdate(*args, **kw_args):
+print(datetime.datetime.today(), *args, sep=' ', **kw_args)
+
 def usage():
printerr("Usage is: export-to-sqlite.py  [] 
[] []");
printerr("where:columns 'all' or 'branches'");
@@ -105,7 +108,7 @@ def do_query_(q):
return
raise Exception("Query failed: " + q.lastError().text())
 

[PATCH 16/30] perf script python: Add Python3 support to export-to-postgresql.py

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Tony Jones 

Support both Python2 and Python3 in the export-to-postgresql.py script.

The use of 'from __future__' implies the minimum supported Python2 version
is now v2.6

Signed-off-by: Tony Jones 
Link: http://lkml.kernel.org/r/20190309000518.2438-3-to...@suse.de
Signed-off-by: Adrian Hunter 
Signed-off-by: Seeteena Thoufeek 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../scripts/python/export-to-postgresql.py| 58 +--
 1 file changed, 41 insertions(+), 17 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 390a351d15ea..00ab972a2eba 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -10,6 +10,8 @@
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 # more details.
 
+from __future__ import print_function
+
 import os
 import sys
 import struct
@@ -199,6 +201,18 @@ import datetime
 
 from PySide.QtSql import *
 
+if sys.version_info < (3, 0):
+   def toserverstr(str):
+   return str
+   def toclientstr(str):
+   return str
+else:
+   # Assume UTF-8 server_encoding and client_encoding
+   def toserverstr(str):
+   return bytes(str, "UTF_8")
+   def toclientstr(str):
+   return bytes(str, "UTF_8")
+
 # Need to access PostgreSQL C library directly to use COPY FROM STDIN
 from ctypes import *
 libpq = CDLL("libpq.so.5")
@@ -234,12 +248,14 @@ perf_db_export_mode = True
 perf_db_export_calls = False
 perf_db_export_callchains = False
 
+def printerr(*args, **kw_args):
+   print(*args, file=sys.stderr, **kw_args)
 
 def usage():
-   print >> sys.stderr, "Usage is: export-to-postgresql.py  
[] [] []"
-   print >> sys.stderr, "where:columns 'all' or 'branches'"
-   print >> sys.stderr, "  calls   'calls' => create calls 
and call_paths table"
-   print >> sys.stderr, "  callchains  'callchains' => create 
call_paths table"
+   printerr("Usage is: export-to-postgresql.py  [] 
[] []")
+   printerr("where:columns 'all' or 'branches'")
+   printerr("  calls   'calls' => create calls and 
call_paths table")
+   printerr("  callchains  'callchains' => create 
call_paths table")
raise Exception("Too few arguments")
 
 if (len(sys.argv) < 2):
@@ -273,7 +289,7 @@ def do_query(q, s):
return
raise Exception("Query failed: " + q.lastError().text())
 
-print datetime.datetime.today(), "Creating database..."
+print(datetime.datetime.today(), "Creating database...")
 
 db = QSqlDatabase.addDatabase('QPSQL')
 query = QSqlQuery(db)
@@ -506,12 +522,12 @@ do_query(query, 'CREATE VIEW samples_view AS '
' FROM samples')
 
 
-file_header = struct.pack("!11sii", "PGCOPY\n\377\r\n\0", 0, 0)
-file_trailer = "\377\377"
+file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0)
+file_trailer = b"\377\377"
 
 def open_output_file(file_name):
path_name = output_dir_name + "/" + file_name
-   file = open(path_name, "w+")
+   file = open(path_name, "wb+")
file.write(file_header)
return file
 
@@ -526,13 +542,13 @@ def copy_output_file_direct(file, table_name):
 
 # Use COPY FROM STDIN because security may prevent postgres from accessing the 
files directly
 def copy_output_file(file, table_name):
-   conn = PQconnectdb("dbname = " + dbname)
+   conn = PQconnectdb(toclientstr("dbname = " + dbname))
if (PQstatus(conn)):
raise Exception("COPY FROM STDIN PQconnectdb failed")
file.write(file_trailer)
file.seek(0)
sql = "COPY " + table_name + " FROM STDIN (FORMAT 'binary')"
-   res = PQexec(conn, sql)
+   res = PQexec(conn, toclientstr(sql))
if (PQresultStatus(res) != 4):
raise Exception("COPY FROM STDIN PQexec failed")
data = file.read(65536)
@@ -566,7 +582,7 @@ if perf_db_export_calls:
call_file   = open_output_file("call_table.bin")
 
 def trace_begin():
-   print datetime.datetime.today(), "Writing to intermediate files..."
+   print(datetime.datetime.today(), "Writing to intermediate files...")
# id == 0 means unknown.  It is easier to create records for them than 
replace the zeroes with NULLs
evsel_table(0, "unknown")
machine_table(0, 0, "unknown")
@@ -582,7 +598,7 @@ def trace_begin():
 unhandled_count = 0
 
 def trace_end():
-   print datetime.datetime.today(), "Copying to database..."
+   print(datetime.datetime.today(), "Copying to database...")
copy_output_file(evsel_file,"selected_events")
copy_output_file(machine_file,  "machines")
copy_output_file(thread_file,   "threads")
@@ -597,7 +613,7 @@ def trace_end():
if perf_db_export_calls:

[PATCH 15/30] perf script python: Add Python3 support to exported-sql-viewer.py

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Tony Jones 

Support both Python2 and Python3 in the exported-sql-viewer.py script.

The use of 'from __future__' implies the minimum supported Python2 version
is now v2.6

Signed-off-by: Tony Jones 
Acked-by: Adrian Hunter 
Link: http://lkml.kernel.org/r/20190309000518.2438-2-to...@suse.de
Signed-off-by: Seeteena Thoufeek 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../scripts/python/exported-sql-viewer.py | 42 ---
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py 
b/tools/perf/scripts/python/exported-sql-viewer.py
index afec9479ca7f..e38518cdcbc3 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -88,11 +88,20 @@
 #  
7fab593ea956 48 89 15 3b 13 22 00movq  %rdx, 
0x22133b(%rip)
 # 8107675243232  2ls   22011  22011  hardware interrupt No 
7fab593ea956 _dl_start+0x26 (ld-2.19.so) -> 86a012e0 page_fault 
([kernel])
 
+from __future__ import print_function
+
 import sys
 import weakref
 import threading
 import string
-import cPickle
+try:
+   # Python2
+   import cPickle as pickle
+   # size of pickled integer big enough for record size
+   glb_nsz = 8
+except ImportError:
+   import pickle
+   glb_nsz = 16
 import re
 import os
 from PySide.QtCore import *
@@ -102,6 +111,15 @@ from decimal import *
 from ctypes import *
 from multiprocessing import Process, Array, Value, Event
 
+# xrange is range in Python3
+try:
+   xrange
+except NameError:
+   xrange = range
+
+def printerr(*args, **keyword_args):
+   print(*args, file=sys.stderr, **keyword_args)
+
 # Data formatting helpers
 
 def tohex(ip):
@@ -1004,10 +1022,6 @@ class ChildDataItemFinder():
 
 glb_chunk_sz = 1
 
-# size of pickled integer big enough for record size
-
-glb_nsz = 8
-
 # Background process for SQL data fetcher
 
 class SQLFetcherProcess():
@@ -1066,7 +1080,7 @@ class SQLFetcherProcess():
return True
if space >= glb_nsz:
# Use 0 (or space < glb_nsz) to mean there is 
no more at the top of the buffer
-   nd = cPickle.dumps(0, cPickle.HIGHEST_PROTOCOL)
+   nd = pickle.dumps(0, pickle.HIGHEST_PROTOCOL)
self.buffer[self.local_head : self.local_head + 
len(nd)] = nd
self.local_head = 0
if self.local_tail - self.local_head > sz:
@@ -1084,9 +1098,9 @@ class SQLFetcherProcess():
self.wait_event.wait()
 
def AddToBuffer(self, obj):
-   d = cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL)
+   d = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
n = len(d)
-   nd = cPickle.dumps(n, cPickle.HIGHEST_PROTOCOL)
+   nd = pickle.dumps(n, pickle.HIGHEST_PROTOCOL)
sz = n + glb_nsz
self.WaitForSpace(sz)
pos = self.local_head
@@ -1198,12 +1212,12 @@ class SQLFetcher(QObject):
pos = self.local_tail
if len(self.buffer) - pos < glb_nsz:
pos = 0
-   n = cPickle.loads(self.buffer[pos : pos + glb_nsz])
+   n = pickle.loads(self.buffer[pos : pos + glb_nsz])
if n == 0:
pos = 0
-   n = cPickle.loads(self.buffer[0 : glb_nsz])
+   n = pickle.loads(self.buffer[0 : glb_nsz])
pos += glb_nsz
-   obj = cPickle.loads(self.buffer[pos : pos + n])
+   obj = pickle.loads(self.buffer[pos : pos + n])
self.local_tail = pos + n
return obj
 
@@ -2973,7 +2987,7 @@ class DBRef():
 
 def Main():
if (len(sys.argv) < 2):
-   print >> sys.stderr, "Usage is: exported-sql-viewer.py 
{ | --help-only}"
+   printerr("Usage is: exported-sql-viewer.py { | 
--help-only}");
raise Exception("Too few arguments")
 
dbname = sys.argv[1]
@@ -2986,8 +3000,8 @@ def Main():
 
is_sqlite3 = False
try:
-   f = open(dbname)
-   if f.read(15) == "SQLite format 3":
+   f = open(dbname, "rb")
+   if f.read(15) == b'SQLite format 3':
is_sqlite3 = True
f.close()
except:
-- 
2.20.1



[PATCH 09/30] perf data: Don't store auxtrace index for directory data file

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Jiri Olsa 

We can't store the auxtrace index when we store into multiple files,
because we keep only offset for it, not the file.

The auxtrace data will be processed correctly in the 'pipe' mode.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190308134745.5057-3-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f3f7f3100336..e983c8d71a79 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -392,7 +392,7 @@ static int record__process_auxtrace(struct perf_tool *tool,
size_t padding;
u8 pad[8] = {0};
 
-   if (!perf_data__is_pipe(data)) {
+   if (!perf_data__is_pipe(data) && !perf_data__is_dir(data)) {
off_t file_offset;
int fd = perf_data__fd(data);
int err;
-- 
2.20.1



[PATCH 06/30] perf probe: Fix getting the kernel map

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Adrian Hunter 

Since commit 4d99e4136580 ("perf machine: Workaround missing maps for
x86 PTI entry trampolines"), perf tools has been creating more than one
kernel map, however 'perf probe' assumed there could be only one.

Fix by using machine__kernel_map() to get the main kernel map.

Signed-off-by: Adrian Hunter 
Tested-by: Joseph Qi 
Acked-by: Masami Hiramatsu 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Greg Kroah-Hartman 
Cc: Jiufei Xue 
Cc: Peter Zijlstra 
Cc: sta...@vger.kernel.org
Cc: Xu Yu 
Fixes: 4d99e4136580 ("perf machine: Workaround missing maps for x86 PTI entry 
trampolines")
Fixes: d83212d5dd67 ("kallsyms, x86: Export addresses of PTI entry trampolines")
Link: http://lkml.kernel.org/r/2ed432de-e904-85d2-5c36-5897ddc5b...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/probe-event.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a1b8d9649ca7..198e09ff611e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -160,8 +160,10 @@ static struct map *kernel_get_module_map(const char 
*module)
if (module && strchr(module, '/'))
return dso__new_map(module);
 
-   if (!module)
-   module = "kernel";
+   if (!module) {
+   pos = machine__kernel_map(host_machine);
+   return map__get(pos);
+   }
 
for (pos = maps__first(maps); pos; pos = map__next(pos)) {
/* short_name is "[module]" */
-- 
2.20.1



[PATCH 20/30] tools headers uapi: Sync copy of asm-generic/unistd.h with the kernel sources

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

To get the changes in:

  c8ce48f06503 ("asm-generic: Make time32 syscall numbers optional")

Silencing these tools/perf build warnings:

  Warning: Kernel ABI header at 'tools/arch/arm64/include/uapi/asm/unistd.h' 
differs from latest version at 'arch/arm64/include/uapi/asm/unistd.h'
  diff -u tools/arch/arm64/include/uapi/asm/unistd.h 
arch/arm64/include/uapi/asm/unistd.h
  Warning: Kernel ABI header at 'tools/include/uapi/asm-generic/unistd.h' 
differs from latest version at 'include/uapi/asm-generic/unistd.h'
  diff -u tools/include/uapi/asm-generic/unistd.h 
include/uapi/asm-generic/unistd.h

Test built it under the ubuntu:14.04.4-x-linaro-arm64 cross build
environment and looked at the syscall table at
/tmp/build/perf/arch/arm64/include/generated/asm/syscalls.c, looks ok.

Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Arnd Bergmann 
Cc: Hendrik Brueckner 
Cc: Jiri Olsa 
Cc: Kim Phillips 
Cc: Michael Ellerman 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Ravi Bangoria 
Cc: Thomas Richter 
Link: https://lkml.kernel.org/n/tip-e4w7ngsmkq48bd6st52ty...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/arch/arm64/include/uapi/asm/unistd.h |   2 +
 tools/include/uapi/asm-generic/unistd.h| 149 -
 2 files changed, 118 insertions(+), 33 deletions(-)

diff --git a/tools/arch/arm64/include/uapi/asm/unistd.h 
b/tools/arch/arm64/include/uapi/asm/unistd.h
index dae1584cf017..4703d218663a 100644
--- a/tools/arch/arm64/include/uapi/asm/unistd.h
+++ b/tools/arch/arm64/include/uapi/asm/unistd.h
@@ -17,5 +17,7 @@
 
 #define __ARCH_WANT_RENAMEAT
 #define __ARCH_WANT_NEW_STAT
+#define __ARCH_WANT_SET_GET_RLIMIT
+#define __ARCH_WANT_TIME32_SYSCALLS
 
 #include 
diff --git a/tools/include/uapi/asm-generic/unistd.h 
b/tools/include/uapi/asm-generic/unistd.h
index d90127298f12..12cdf611d217 100644
--- a/tools/include/uapi/asm-generic/unistd.h
+++ b/tools/include/uapi/asm-generic/unistd.h
@@ -38,8 +38,10 @@ __SYSCALL(__NR_io_destroy, sys_io_destroy)
 __SC_COMP(__NR_io_submit, sys_io_submit, compat_sys_io_submit)
 #define __NR_io_cancel 3
 __SYSCALL(__NR_io_cancel, sys_io_cancel)
+#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
 #define __NR_io_getevents 4
-__SC_COMP(__NR_io_getevents, sys_io_getevents, compat_sys_io_getevents)
+__SC_3264(__NR_io_getevents, sys_io_getevents_time32, sys_io_getevents)
+#endif
 
 /* fs/xattr.c */
 #define __NR_setxattr 5
@@ -179,7 +181,7 @@ __SYSCALL(__NR_fchownat, sys_fchownat)
 #define __NR_fchown 55
 __SYSCALL(__NR_fchown, sys_fchown)
 #define __NR_openat 56
-__SC_COMP(__NR_openat, sys_openat, compat_sys_openat)
+__SYSCALL(__NR_openat, sys_openat)
 #define __NR_close 57
 __SYSCALL(__NR_close, sys_close)
 #define __NR_vhangup 58
@@ -222,10 +224,12 @@ __SC_COMP(__NR_pwritev, sys_pwritev, compat_sys_pwritev)
 __SYSCALL(__NR3264_sendfile, sys_sendfile64)
 
 /* fs/select.c */
+#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
 #define __NR_pselect6 72
-__SC_COMP(__NR_pselect6, sys_pselect6, compat_sys_pselect6)
+__SC_COMP_3264(__NR_pselect6, sys_pselect6_time32, sys_pselect6, 
compat_sys_pselect6_time32)
 #define __NR_ppoll 73
-__SC_COMP(__NR_ppoll, sys_ppoll, compat_sys_ppoll)
+__SC_COMP_3264(__NR_ppoll, sys_ppoll_time32, sys_ppoll, 
compat_sys_ppoll_time32)
+#endif
 
 /* fs/signalfd.c */
 #define __NR_signalfd4 74
@@ -269,16 +273,20 @@ __SC_COMP(__NR_sync_file_range, sys_sync_file_range, \
 /* fs/timerfd.c */
 #define __NR_timerfd_create 85
 __SYSCALL(__NR_timerfd_create, sys_timerfd_create)
+#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
 #define __NR_timerfd_settime 86
-__SC_COMP(__NR_timerfd_settime, sys_timerfd_settime, \
- compat_sys_timerfd_settime)
+__SC_3264(__NR_timerfd_settime, sys_timerfd_settime32, \
+ sys_timerfd_settime)
 #define __NR_timerfd_gettime 87
-__SC_COMP(__NR_timerfd_gettime, sys_timerfd_gettime, \
- compat_sys_timerfd_gettime)
+__SC_3264(__NR_timerfd_gettime, sys_timerfd_gettime32, \
+ sys_timerfd_gettime)
+#endif
 
 /* fs/utimes.c */
+#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
 #define __NR_utimensat 88
-__SC_COMP(__NR_utimensat, sys_utimensat, compat_sys_utimensat)
+__SC_3264(__NR_utimensat, sys_utimensat_time32, sys_utimensat)
+#endif
 
 /* kernel/acct.c */
 #define __NR_acct 89
@@ -309,8 +317,10 @@ __SYSCALL(__NR_set_tid_address, sys_set_tid_address)
 __SYSCALL(__NR_unshare, sys_unshare)
 
 /* kernel/futex.c */
+#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
 #define __NR_futex 98
-__SC_COMP(__NR_futex, sys_futex, compat_sys_futex)
+__SC_3264(__NR_futex, sys_futex_time32, sys_futex)
+#endif
 #define __NR_set_robust_list 99
 __SC_COMP(__NR_set_robust_list, sys_set_robust_list, \
  compat_sys_set_robust_list)
@@ -319,8 +329,10 @@ __SC_COMP(__NR_get_robust_list, sys_get_robust_list, \
  compat_sys_get_robust_list)
 
 /* kernel/hrtimer.c */
+#if 

[PATCH 07/30] perf vendor events amd: perf PMU events for AMD Family 17h

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Martin Liška 

Thi patch adds PMC events for AMD Family 17 CPUs as defined in [1].  It
covers events described in section: 2.1.13. Regex pattern in mapfile.csv
covers all CPUs of the family.

[1] https://support.amd.com/TechDocs/54945_PPR_Family_17h_Models_00h-0Fh.pdf

Signed-off-by: Martin Liška 
Acked-by: Borislav Petkov 
Cc: Jiri Olsa 
Cc: Jon Grimm 
Cc: Martin Jambor 
Cc: William Cohen 
Link: https://lkml.kernel.org/r/d65873ca-e402-b198-4fe9-8c4af8125...@suse.cz
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../pmu-events/arch/x86/amdfam17h/branch.json |  12 +
 .../pmu-events/arch/x86/amdfam17h/cache.json  | 287 ++
 .../pmu-events/arch/x86/amdfam17h/core.json   | 134 
 .../arch/x86/amdfam17h/floating-point.json| 168 ++
 .../pmu-events/arch/x86/amdfam17h/memory.json | 162 ++
 .../pmu-events/arch/x86/amdfam17h/other.json  |  65 
 tools/perf/pmu-events/arch/x86/mapfile.csv|   1 +
 7 files changed, 829 insertions(+)
 create mode 100644 tools/perf/pmu-events/arch/x86/amdfam17h/branch.json
 create mode 100644 tools/perf/pmu-events/arch/x86/amdfam17h/cache.json
 create mode 100644 tools/perf/pmu-events/arch/x86/amdfam17h/core.json
 create mode 100644 tools/perf/pmu-events/arch/x86/amdfam17h/floating-point.json
 create mode 100644 tools/perf/pmu-events/arch/x86/amdfam17h/memory.json
 create mode 100644 tools/perf/pmu-events/arch/x86/amdfam17h/other.json

diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/branch.json 
b/tools/perf/pmu-events/arch/x86/amdfam17h/branch.json
new file mode 100644
index ..93ddfd8053ca
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/branch.json
@@ -0,0 +1,12 @@
+[
+  {
+"EventName": "bp_l1_btb_correct",
+"EventCode": "0x8a",
+"BriefDescription": "L1 BTB Correction."
+  },
+  {
+"EventName": "bp_l2_btb_correct",
+"EventCode": "0x8b",
+"BriefDescription": "L2 BTB Correction."
+  }
+]
diff --git a/tools/perf/pmu-events/arch/x86/amdfam17h/cache.json 
b/tools/perf/pmu-events/arch/x86/amdfam17h/cache.json
new file mode 100644
index ..fad4af9142cb
--- /dev/null
+++ b/tools/perf/pmu-events/arch/x86/amdfam17h/cache.json
@@ -0,0 +1,287 @@
+[
+  {
+"EventName": "ic_fw32",
+"EventCode": "0x80",
+"BriefDescription": "The number of 32B fetch windows transferred from IC 
pipe to DE instruction decoder (includes non-cacheable and cacheable fill 
responses)."
+  },
+  {
+"EventName": "ic_fw32_miss",
+"EventCode": "0x81",
+"BriefDescription": "The number of 32B fetch windows tried to read the L1 
IC and missed in the full tag."
+  },
+  {
+"EventName": "ic_cache_fill_l2",
+"EventCode": "0x82",
+"BriefDescription": "The number of 64 byte instruction cache line was 
fulfilled from the L2 cache."
+  },
+  {
+"EventName": "ic_cache_fill_sys",
+"EventCode": "0x83",
+"BriefDescription": "The number of 64 byte instruction cache line 
fulfilled from system memory or another cache."
+  },
+  {
+"EventName": "bp_l1_tlb_miss_l2_hit",
+"EventCode": "0x84",
+"BriefDescription": "The number of instruction fetches that miss in the L1 
ITLB but hit in the L2 ITLB."
+  },
+  {
+"EventName": "bp_l1_tlb_miss_l2_miss",
+"EventCode": "0x85",
+"BriefDescription": "The number of instruction fetches that miss in both 
the L1 and L2 TLBs."
+  },
+  {
+"EventName": "bp_snp_re_sync",
+"EventCode": "0x86",
+"BriefDescription": "The number of pipeline restarts caused by 
invalidating probes that hit on the instruction stream currently being 
executed. This would happen if the active instruction stream was being modified 
by another processor in an MP system - typically a highly unlikely event."
+  },
+  {
+"EventName": "ic_fetch_stall.ic_stall_any",
+"EventCode": "0x87",
+"BriefDescription": "IC pipe was stalled during this clock cycle for any 
reason (nothing valid in pipe ICM1).",
+"PublicDescription": "Instruction Pipe Stall. IC pipe was stalled during 
this clock cycle for any reason (nothing valid in pipe ICM1).",
+"UMask": "0x4"
+  },
+  {
+"EventName": "ic_fetch_stall.ic_stall_dq_empty",
+"EventCode": "0x87",
+"BriefDescription": "IC pipe was stalled during this clock cycle 
(including IC to OC fetches) due to DQ empty.",
+"PublicDescription": "Instruction Pipe Stall. IC pipe was stalled during 
this clock cycle (including IC to OC fetches) due to DQ empty.",
+"UMask": "0x2"
+  },
+  {
+"EventName": "ic_fetch_stall.ic_stall_back_pressure",
+"EventCode": "0x87",
+"BriefDescription": "IC pipe was stalled during this clock cycle 
(including IC to OC fetches) due to back-pressure.",
+"PublicDescription": "Instruction Pipe Stall. IC pipe was stalled during 
this clock cycle (including IC to OC fetches) due to back-pressure.",
+"UMask": "0x1"
+  },
+  {
+"EventName": "ic_cache_inval.l2_invalidating_probe",
+"EventCode": "0x8c",
+"BriefDescription": "IC 

[PATCH 08/30] perf data: Support having perf.data stored as a directory

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Jiri Olsa 

The caller needs to set 'struct perf_data::is_dir flag and the path will
be treated as a directory.

The 'struct perf_data::file' is initialized and open as 'path/header'
file.

Add a check to the direcory interface functions to check the is_dir flag.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190308134745.5057-2-jo...@kernel.org
[ Be consistent on how to signal failure, i.e. use -1 and let users check errno 
]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/data.c| 49 ++-
 tools/perf/util/data.h|  6 +
 tools/perf/util/session.c |  4 
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index e098e189f93e..18fa8d4614eb 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -34,6 +34,9 @@ int perf_data__create_dir(struct perf_data *data, int nr)
struct perf_data_file *files = NULL;
int i, ret = -1;
 
+   if (WARN_ON(!data->is_dir))
+   return -EINVAL;
+
files = zalloc(nr * sizeof(*files));
if (!files)
return -ENOMEM;
@@ -69,6 +72,9 @@ int perf_data__open_dir(struct perf_data *data)
DIR *dir;
int nr = 0;
 
+   if (WARN_ON(!data->is_dir))
+   return -EINVAL;
+
dir = opendir(data->path);
if (!dir)
return -EINVAL;
@@ -173,6 +179,16 @@ static int check_backup(struct perf_data *data)
return 0;
 }
 
+static bool is_dir(struct perf_data *data)
+{
+   struct stat st;
+
+   if (stat(data->path, ))
+   return false;
+
+   return (st.st_mode & S_IFMT) == S_IFDIR;
+}
+
 static int open_file_read(struct perf_data *data)
 {
struct stat st;
@@ -254,6 +270,30 @@ static int open_file_dup(struct perf_data *data)
return open_file(data);
 }
 
+static int open_dir(struct perf_data *data)
+{
+   int ret;
+
+   /*
+* So far we open only the header, so we can read the data version and
+* layout.
+*/
+   if (asprintf(>file.path, "%s/header", data->path) < 0)
+   return -1;
+
+   if (perf_data__is_write(data) &&
+   mkdir(data->path, S_IRWXU) < 0)
+   return -1;
+
+   ret = open_file(data);
+
+   /* Cleanup whatever we managed to create so far. */
+   if (ret && perf_data__is_write(data))
+   rm_rf_perf_data(data->path);
+
+   return ret;
+}
+
 int perf_data__open(struct perf_data *data)
 {
if (check_pipe(data))
@@ -265,11 +305,18 @@ int perf_data__open(struct perf_data *data)
if (check_backup(data))
return -1;
 
-   return open_file_dup(data);
+   if (perf_data__is_read(data))
+   data->is_dir = is_dir(data);
+
+   return perf_data__is_dir(data) ?
+  open_dir(data) : open_file_dup(data);
 }
 
 void perf_data__close(struct perf_data *data)
 {
+   if (perf_data__is_dir(data))
+   perf_data__close_dir(data);
+
zfree(>file.path);
close(data->file.fd);
 }
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 14b47be2bd69..06aefeda311f 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -19,6 +19,7 @@ struct perf_data {
const char  *path;
struct perf_data_filefile;
bool is_pipe;
+   bool is_dir;
bool force;
enum perf_data_mode  mode;
 
@@ -43,6 +44,11 @@ static inline int perf_data__is_pipe(struct perf_data *data)
return data->is_pipe;
 }
 
+static inline bool perf_data__is_dir(struct perf_data *data)
+{
+   return data->is_dir;
+}
+
 static inline int perf_data__fd(struct perf_data *data)
 {
return data->file.fd;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index db643f3c2b95..de777bdc0ed3 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -152,6 +152,10 @@ struct perf_session *perf_session__new(struct perf_data 
*data,
}
 

perf_evlist__init_trace_event_sample_raw(session->evlist);
+
+   /* Open the directory data. */
+   if (data->is_dir && perf_data__open_dir(data))
+   goto out_delete;
}
} else  {
session->machines.host.env = _env;
-- 
2.20.1



[PATCH 11/30] perf data: Make perf_data__size() work over directory

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Jiri Olsa 

Make perf_data__size() return proper size for directory data, summing up
all the individual file sizes.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190308134745.5057-5-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/data.c | 17 +
 tools/perf/util/data.h |  6 +-
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 5d0f26aef77f..b71c441cafbb 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -393,3 +393,20 @@ int perf_data__switch(struct perf_data *data,
free(new_filepath);
return ret;
 }
+
+unsigned long perf_data__size(struct perf_data *data)
+{
+   u64 size = data->file.size;
+   int i;
+
+   if (!data->is_dir)
+   return size;
+
+   for (i = 0; i < data->dir.nr; i++) {
+   struct perf_data_file *file = >dir.files[i];
+
+   size += file->size;
+   }
+
+   return size;
+}
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 0deeb1af9f54..d342469bdfda 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -54,11 +54,6 @@ static inline int perf_data__fd(struct perf_data *data)
return data->file.fd;
 }
 
-static inline unsigned long perf_data__size(struct perf_data *data)
-{
-   return data->file.size;
-}
-
 int perf_data__open(struct perf_data *data);
 void perf_data__close(struct perf_data *data);
 ssize_t perf_data__write(struct perf_data *data,
@@ -80,4 +75,5 @@ int perf_data__create_dir(struct perf_data *data, int nr);
 int perf_data__open_dir(struct perf_data *data);
 void perf_data__close_dir(struct perf_data *data);
 int perf_data__update_dir(struct perf_data *data);
+unsigned long perf_data__size(struct perf_data *data);
 #endif /* __PERF_DATA_H */
-- 
2.20.1



[PATCH 10/30] perf data: Add perf_data__update_dir() function

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Jiri Olsa 

Add perf_data__update_dir() to update the size for every file within the
perf.data directory.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190308134745.5057-4-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/data.c | 20 
 tools/perf/util/data.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 18fa8d4614eb..5d0f26aef77f 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -124,6 +124,26 @@ int perf_data__open_dir(struct perf_data *data)
return ret;
 }
 
+int perf_data__update_dir(struct perf_data *data)
+{
+   int i;
+
+   if (WARN_ON(!data->is_dir))
+   return -EINVAL;
+
+   for (i = 0; i < data->dir.nr; i++) {
+   struct perf_data_file *file = >dir.files[i];
+   struct stat st;
+
+   if (fstat(file->fd, ))
+   return -1;
+
+   file->size = st.st_size;
+   }
+
+   return 0;
+}
+
 static bool check_pipe(struct perf_data *data)
 {
struct stat st;
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 06aefeda311f..0deeb1af9f54 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -79,4 +79,5 @@ int perf_data__switch(struct perf_data *data,
 int perf_data__create_dir(struct perf_data *data, int nr);
 int perf_data__open_dir(struct perf_data *data);
 void perf_data__close_dir(struct perf_data *data);
+int perf_data__update_dir(struct perf_data *data);
 #endif /* __PERF_DATA_H */
-- 
2.20.1



[PATCH 12/30] perf header: Add DIR_FORMAT feature to describe directory data

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Jiri Olsa 

The data files layout is described by HEADER_DIR_FORMAT feature.
Currently it holds only version number (1):

 uint64_t version;

The current version holds only version value (1) means that data files:

  - Follow the 'data.*' name format.

  - Contain raw events data in standard perf format as read from kernel
(and need to be sorted)

Future versions are expected to describe different data files layout
according to special needs.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190308134745.5057-6-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c |  2 ++
 tools/perf/util/data.c  | 10 +++--
 tools/perf/util/data.h  |  1 +
 tools/perf/util/header.c| 44 -
 tools/perf/util/header.h|  5 +
 5 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e983c8d71a79..a468d882e74f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -837,6 +837,8 @@ static void record__init_features(struct record *rec)
if (!(rec->opts.use_clockid && rec->opts.clockid_res_ns))
perf_header__clear_feat(>header, HEADER_CLOCKID);
 
+   perf_header__clear_feat(>header, HEADER_DIR_FORMAT);
+
perf_header__clear_feat(>header, HEADER_STAT);
 }
 
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index b71c441cafbb..c6b67efea11a 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -14,6 +14,7 @@
 #include "data.h"
 #include "util.h"
 #include "debug.h"
+#include "header.h"
 
 static void close_dir(struct perf_data_file *files, int nr)
 {
@@ -41,8 +42,9 @@ int perf_data__create_dir(struct perf_data *data, int nr)
if (!files)
return -ENOMEM;
 
-   data->dir.files = files;
-   data->dir.nr= nr;
+   data->dir.version = PERF_DIR_VERSION;
+   data->dir.files   = files;
+   data->dir.nr  = nr;
 
for (i = 0; i < nr; i++) {
struct perf_data_file *file = [i];
@@ -75,6 +77,10 @@ int perf_data__open_dir(struct perf_data *data)
if (WARN_ON(!data->is_dir))
return -EINVAL;
 
+   /* The version is provided by DIR_FORMAT feature. */
+   if (WARN_ON(data->dir.version != PERF_DIR_VERSION))
+   return -1;
+
dir = opendir(data->path);
if (!dir)
return -EINVAL;
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index d342469bdfda..6aef8746469f 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -24,6 +24,7 @@ struct perf_data {
enum perf_data_mode  mode;
 
struct {
+   u64  version;
struct perf_data_file   *files;
int  nr;
} dir;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 01b324c275b9..b0683bf4d9f3 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -861,6 +861,21 @@ static int write_clockid(struct feat_fd *ff,
sizeof(ff->ph->env.clockid_res_ns));
 }
 
+static int write_dir_format(struct feat_fd *ff,
+   struct perf_evlist *evlist __maybe_unused)
+{
+   struct perf_session *session;
+   struct perf_data *data;
+
+   session = container_of(ff->ph, struct perf_session, header);
+   data = session->data;
+
+   if (WARN_ON(!perf_data__is_dir(data)))
+   return -1;
+
+   return do_write(ff, >dir.version, sizeof(data->dir.version));
+}
+
 static int cpu_cache_level__sort(const void *a, const void *b)
 {
struct cpu_cache_level *cache_a = (struct cpu_cache_level *)a;
@@ -1341,6 +1356,17 @@ static void print_clockid(struct feat_fd *ff, FILE *fp)
ff->ph->env.clockid_res_ns * 1000);
 }
 
+static void print_dir_format(struct feat_fd *ff, FILE *fp)
+{
+   struct perf_session *session;
+   struct perf_data *data;
+
+   session = container_of(ff->ph, struct perf_session, header);
+   data = session->data;
+
+   fprintf(fp, "# directory data version : %"PRIu64"\n", 
data->dir.version);
+}
+
 static void free_event_desc(struct perf_evsel *events)
 {
struct perf_evsel *evsel;
@@ -2373,6 +2399,21 @@ static int process_clockid(struct feat_fd *ff,
return 0;
 }
 
+static int process_dir_format(struct feat_fd *ff,
+ void *_data __maybe_unused)
+{
+   struct perf_session *session;
+   struct perf_data *data;
+
+   session = container_of(ff->ph, struct perf_session, header);
+   data = session->data;
+
+   if (WARN_ON(!perf_data__is_dir(data)))
+   return -1;
+
+   return do_read_u64(ff, >dir.version);
+}
+
 struct feature_ops {
 

[PATCH 13/30] perf session: Add process callback to reader object

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Jiri Olsa 

Adding callback function to reader object so callers can process data in
different ways.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190308134745.5057-7-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/session.c | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index de777bdc0ed3..0ec34227bd60 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1847,10 +1847,17 @@ fetch_mmaped_event(struct perf_session *session,
 #define NUM_MMAPS 128
 #endif
 
+struct reader;
+
+typedef s64 (*reader_cb_t)(struct perf_session *session,
+  union perf_event *event,
+  u64 file_offset);
+
 struct reader {
-   int fd;
-   u64 data_size;
-   u64 data_offset;
+   int  fd;
+   u64  data_size;
+   u64  data_offset;
+   reader_cb_t  process;
 };
 
 static int
@@ -1921,7 +1928,7 @@ reader__process_events(struct reader *rd, struct 
perf_session *session,
size = event->header.size;
 
if (size < sizeof(struct perf_event_header) ||
-   (skip = perf_session__process_event(session, event, file_pos)) < 0) 
{
+   (skip = rd->process(session, event, file_pos)) < 0) {
pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
   file_offset + head, event->header.size,
   event->header.type);
@@ -1947,12 +1954,20 @@ reader__process_events(struct reader *rd, struct 
perf_session *session,
return err;
 }
 
+static s64 process_simple(struct perf_session *session,
+ union perf_event *event,
+ u64 file_offset)
+{
+   return perf_session__process_event(session, event, file_offset);
+}
+
 static int __perf_session__process_events(struct perf_session *session)
 {
struct reader rd = {
.fd = perf_data__fd(session->data),
.data_size  = session->header.data_size,
.data_offset= session->header.data_offset,
+   .process= process_simple,
};
struct ordered_events *oe = >ordered_events;
struct perf_tool *tool = session->tool;
-- 
2.20.1



[PATCH 14/30] perf report: Use less for scripts output

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

The UI viewer for scripts output has a lot of limitations: limited size,
no search or save function, slow, and various other issues.

Just use 'less' to display directly on the terminal instead.

This won't work in GTK mode, but GTK doesn't support these context menus
anyways. If that is ever done could use an terminal for the output.

Signed-off-by: Andi Kleen 
Acked-by: Feng Tang 
Cc: Jiri Olsa 
Link: http://lkml.kernel.org/r/20190309055628.21617-8-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/scripts.c | 130 ---
 1 file changed, 17 insertions(+), 113 deletions(-)

diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index 90a32ac69e76..7f36630694bf 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -1,35 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
-#include 
-#include 
-#include 
-#include 
 #include "../../util/sort.h"
 #include "../../util/util.h"
 #include "../../util/hist.h"
 #include "../../util/debug.h"
 #include "../../util/symbol.h"
 #include "../browser.h"
-#include "../helpline.h"
 #include "../libslang.h"
 
-/* 2048 lines should be enough for a script output */
-#define MAX_LINES  2048
-
-/* 160 bytes for one output line */
-#define AVERAGE_LINE_LEN   160
-
-struct script_line {
-   struct list_head node;
-   char line[AVERAGE_LINE_LEN];
-};
-
-struct perf_script_browser {
-   struct ui_browser b;
-   struct list_head entries;
-   const char *script_name;
-   int nr_lines;
-};
-
 #define SCRIPT_NAMELEN 128
 #define SCRIPT_MAX_NO  64
 /*
@@ -73,69 +50,29 @@ static int list_scripts(char *script_name)
return ret;
 }
 
-static void script_browser__write(struct ui_browser *browser,
-  void *entry, int row)
+static void run_script(char *cmd)
 {
-   struct script_line *sline = list_entry(entry, struct script_line, node);
-   bool current_entry = ui_browser__is_current_entry(browser, row);
-
-   ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
-  HE_COLORSET_NORMAL);
-
-   ui_browser__write_nstring(browser, sline->line, browser->width);
+   pr_debug("Running %s\n", cmd);
+   SLang_reset_tty();
+   if (system(cmd) < 0)
+   pr_warning("Cannot run %s\n", cmd);
+   /*
+* SLang doesn't seem to reset the whole terminal, so be more
+* forceful to get back to the original state.
+*/
+   printf("\033[c\033[H\033[J");
+   fflush(stdout);
+   SLang_init_tty(0, 0, 0);
+   SLsmg_refresh();
 }
 
-static int script_browser__run(struct perf_script_browser *browser)
-{
-   int key;
-
-   if (ui_browser__show(>b, browser->script_name,
-"Press ESC to exit") < 0)
-   return -1;
-
-   while (1) {
-   key = ui_browser__run(>b, 0);
-
-   /* We can add some special key handling here if needed */
-   break;
-   }
-
-   ui_browser__hide(>b);
-   return key;
-}
-
-
 int script_browse(const char *script_opt)
 {
char cmd[SCRIPT_FULLPATH_LEN*2], script_name[SCRIPT_FULLPATH_LEN];
-   char *line = NULL;
-   size_t len = 0;
-   ssize_t retlen;
-   int ret = -1, nr_entries = 0;
-   FILE *fp;
-   void *buf;
-   struct script_line *sline;
-
-   struct perf_script_browser script = {
-   .b = {
-   .refresh= ui_browser__list_head_refresh,
-   .seek   = ui_browser__list_head_seek,
-   .write  = script_browser__write,
-   },
-   .script_name = script_name,
-   };
-
-   INIT_LIST_HEAD();
-
-   /* Save each line of the output in one struct script_line object. */
-   buf = zalloc((sizeof(*sline)) * MAX_LINES);
-   if (!buf)
-   return -1;
-   sline = buf;
 
memset(script_name, 0, SCRIPT_FULLPATH_LEN);
if (list_scripts(script_name))
-   goto exit;
+   return -1;
 
sprintf(cmd, "perf script -s %s ", script_name);
 
@@ -147,42 +84,9 @@ int script_browse(const char *script_opt)
strcat(cmd, input_name);
}
 
-   strcat(cmd, " 2>&1");
-
-   fp = popen(cmd, "r");
-   if (!fp)
-   goto exit;
-
-   while ((retlen = getline(, , fp)) != -1) {
-   strncpy(sline->line, line, AVERAGE_LINE_LEN);
-
-   /* If one output line is very large, just cut it short */
-   if (retlen >= AVERAGE_LINE_LEN) {
-   sline->line[AVERAGE_LINE_LEN - 1] = '\0';
-   sline->line[AVERAGE_LINE_LEN - 2] = '\n';
-   }
-   list_add_tail(>node, );
-
-   if (script.b.width < retlen)
-   

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

2019-03-11 Thread Arnaldo Carvalho de Melo
Hi Ingo,

Please consider pulling,

Best regards,

- Arnaldo

Test results at the end of this message, as usual.

The following changes since commit b339da480315505aa28a723a983217ebcff95c86:

  Merge tag 'perf-core-for-mingo-5.1-20190307' of 
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent 
(2019-03-09 17:00:17 +0100)

are available in the Git repository at:

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

for you to fetch changes up to dfcbc2f2994b8a3af3605a26dc29c07ad7378bf4:

  tools lib bpf: Fix the build by adding a missing stdarg.h include (2019-03-11 
17:14:31 -0300)


perf/core improvements and fixes:

kernel:

  Stephane Eranian :

  - Restore mmap record type correctly when handling PERF_RECORD_MMAP2
events, as the same template is used for all the threads interested
in mmap events, some may want just PERF_RECORD_MMAP, while some
may want the extra info in MMAP2 records.

perf probe:

  Adrian Hunter:

  - Fix getting the kernel map, because since changes related to x86 PTI
entry trampolines handling, there are more than one kernel map.

perf script:

  Andi Kleen:

  - Support insn output for normal samples, i.e.:

perf script -F ip,sym,insn --xed

Will fetch the sample IP from the thread address space and feed it
to Intel's XED disassembler, producing lines such as:

  a4068804 native_write_msrwrmsr
  a415b95e __hrtimer_next_event_base   movq  0x18(%rax), %rdx

That match 'perf annotate's output.

  - Make the --cpu filter apply to  PERF_RECORD_COMM/FORK/... events, in
addition to PERF_RECORD_SAMPLE.

perf report:

  - Add a new --samples option to save a small random number of samples
per hist entry, using a reservoir technique to select a representative
number of samples.

Then allow browsing the samples using 'perf script' as part of the hist
entry context menu. This automatically adds the right filters, so only
the thread or CPU of the sample is displayed. Then we use less' search
functionality to directly jump to the time stamp of the selected sample.

It uses different menus for assembler and source display.  Assembler
needs xed installed and source needs debuginfo.

  - Fix the UI browser scripts pop up menu when there are many scripts
available.

perf report:

  Andi Kleen:

  - Add 'time' sort option. E.g.:

% perf report --sort time,overhead,symbol --time-quantum 1ms --stdio
...
 0.67%  277061.87300  [.] _dl_start
 0.50%  277061.87300  [.] f1
 0.50%  277061.87300  [.] f2
 0.33%  277061.87300  [.] main
 0.29%  277061.87300  [.] _dl_lookup_symbol_x
 0.29%  277061.87300  [.] dl_main
 0.29%  277061.87300  [.] do_lookup_x
 0.17%  277061.87300  [.] _dl_debug_initialize
 0.17%  277061.87300  [.] _dl_init_paths
 0.08%  277061.87300  [.] check_match
 0.04%  277061.87300  [.] _dl_count_modids
 1.33%  277061.87400  [.] f1
 1.33%  277061.87400  [.] f2
 1.33%  277061.87400  [.] main
 1.17%  277061.87500  [.] main
 1.08%  277061.87500  [.] f1
 1.08%  277061.87500  [.] f2
 1.00%  277061.87600  [.] main
 0.83%  277061.87600  [.] f1
 0.83%  277061.87600  [.] f2
 1.00%  277061.87700  [.] main

tools headers:

  Arnaldo Carvalho de Melo:

  - Update x86's syscall_64.tbl, no change in tools/perf behaviour.

  -  Sync copies asm-generic/unistd.h and linux/in with the kernel sources.

perf data:

  Jiri Olsa:

  - Prep work to support having perf.data stored as a directory, with one
file per CPU, that ultimately will allow having one ring buffer reading
thread per CPU.

Vendor events:

  Martin Liška:

  - perf PMU events for AMD Family 17h.

perf script python:

  Tony Jones:

  - Add python3 support for the remaining Intel PT related scripts, with
these we should have a clean build of perf with python3 while still
supporting the build with python2.

libbpf:

  Arnaldo Carvalho de Melo:

  - Fix the build on uCLibc, adding the missing stdarg.h since we use
va_list in one typedef.

Signed-off-by: Arnaldo Carvalho de Melo 


Adrian Hunter (1):
  perf probe: Fix getting the kernel map

Andi Kleen (14):
  perf script: Support insn output for normal samples
  perf report: Support output in nanoseconds
  perf time-utils: Add utility function to print time stamps in nanoseconds
  perf report: Parse time quantum
  perf report: Use less for scripts output
  perf script: Filter COMM/FORK/.. events by CPU
  perf report: Support time sort key
  perf report: Support running scripts for current time range
  perf report: Support builtin perf script in scripts menu

[PATCH 02/30] perf script: Support insn output for normal samples

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

perf script -F +insn was only working for PT traces because the PT
instruction decoder was filling in the insn/insn_len sample attributes.
Support it for non PT samples too on x86 using the existing x86
instruction decoder.

This adds some extra checking to ensure that we don't try to decode
instructions when using perf.data from a different architecture.

  % perf record -a sleep 1
  % perf script -F ip,sym,insn --xed
   811704c9 remote_function   movl  %eax, 0x18(%rbx)
   8100bb50 intel_bts_enable_localretq
   81048612 native_apic_mem_write movl  %esi, 
-0xa04000(%rdi)
   81048612 native_apic_mem_write movl  %esi, 
-0xa04000(%rdi)
   81048612 native_apic_mem_write movl  %esi, 
-0xa04000(%rdi)
   810f1f79 generic_exec_single   xor %eax, %eax
   811704c9 remote_function   movl  %eax, 0x18(%rbx)
   8100bb34 intel_bts_enable_localmovl  0x2000(%rax), 
%edx
   81048610 native_apic_mem_write mov %edi, %edi
  ...

Committer testing:

Before:

  # perf script -F ip,sym,insn --xed | head -5
   a4068804 native_write_msraddb  %al, (%rax)
   a4068804 native_write_msraddb  %al, (%rax)
   a4068804 native_write_msraddb  %al, (%rax)
   a4068806 native_write_msraddb  %al, (%rax)
   a4068806 native_write_msraddb  %al, (%rax)
  # perf script -F ip,sym,insn --xed | grep -v "addb  %al, (%rax)"
  #

After:

  # perf script -F ip,sym,insn --xed | head -5
   a4068804 native_write_msrwrmsr
   a4068804 native_write_msrwrmsr
   a4068804 native_write_msrwrmsr
   a4068806 native_write_msrnopl  %eax, (%rax,%rax,1)
   a4068806 native_write_msrnopl  %eax, (%rax,%rax,1)
  # perf script -F ip,sym,insn --xed | grep -v "addb  %al, (%rax)" | head -5
   a4068804 native_write_msrwrmsr
   a4068804 native_write_msrwrmsr
   a4068804 native_write_msrwrmsr
   a4068806 native_write_msrnopl  %eax, (%rax,%rax,1)
   a4068806 native_write_msrnopl  %eax, (%rax,%rax,1)
  #

More examples:

  # perf script -F ip,sym,insn --xed | grep -v native_write_msr | head
   a416b90e tick_check_broadcast_expiredbtq  %rax, 
0x1a5f42a(%rip)
   a4956bd0 nmi_cpu_backtrace   pushq  %r13
   a415b95e __hrtimer_next_event_base   movq  0x18(%rax), %rdx
   a4956bf3 nmi_cpu_backtrace   popq  %r12
   a4171d5c smp_call_function_singlepause
   a4956bdd nmi_cpu_backtrace   mov %ebp, %r12d
   a4797e4d menu_select cmp $0x190, %rax
   a4171d5c smp_call_function_singlepause
   a405a7d8 nmi_cpu_backtrace_handler   callq  
0xa4956bd0
   a4797f7a menu_select shr $0x3, %rax
  #

Which matches the annotate output modulo resolving callqs:

  # perf annotate --stdio2 nmi_cpu_backtrace_handler
  Samples: 4  of event 'cycles:ppp', 4000 Hz, Event count (approx.): 35908, 
[percent: local period]
  nmi_cpu_backtrace_handler() /lib/modules/5.0.0+/build/vmlinux
  Percent
  Disassembly of section .text:

  8105a7d0 :
  nmi_cpu_backtrace_handler():
  nmi_trigger_cpumask_backtrace(mask, exclude_self,
nmi_raise_cpu_backtrace);
  }

  static int nmi_cpu_backtrace_handler(unsigned int cmd, struct 
pt_regs *regs)
  {
   24.45  → callq  __fentry__
  if (nmi_cpu_backtrace(regs))
mov%rsi,%rdi
   75.55  → callq  nmi_cpu_backtrace
  return NMI_HANDLED;
movzbl %al,%eax

  return NMI_DONE;
  }
  ← retq
#

  # perf annotate --stdio2 __hrtimer_next_event_base
  Samples: 4  of event 'cycles:ppp', 4000 Hz, Event count (approx.): 767977, 
[percent: local period]
  __hrtimer_next_event_base() /lib/modules/5.0.0+/build/vmlinux
  Percent
  Disassembly of section .text:

  8115b910 <__hrtimer_next_event_base>:
  __hrtimer_next_event_base():

  static ktime_t __hrtimer_next_event_base(struct hrtimer_cpu_base 
*cpu_base,
   const struct hrtimer 
*exclude,
   unsigned int active,
   ktime_t expires_next)
  {
  → callq  __fentry__

  4a:   add$0x1,%r14
   77.31mov0x18(%rax),%rdx
 

Re: [PATCH 0/4] mm: Use slab_list list_head instead of lru

2019-03-11 Thread Tobin C. Harding
On Tue, Mar 12, 2019 at 12:22:23AM +, Roman Gushchin wrote:
> On Mon, Mar 11, 2019 at 04:16:33PM -0700, Matthew Wilcox wrote:
> > On Mon, Mar 11, 2019 at 08:49:23PM +, Roman Gushchin wrote:
> > > The patchset looks good to me, however I'd add some clarifications
> > > why switching from lru to slab_list is safe.
> > > 
> > > My understanding is that the slab_list fields isn't currently in use,
> > > but it's not that obvious that putting slab_list and next/pages/pobjects
> > > fields into a union is safe (for the slub case).
> > 
> > It's already in a union.
> > 
> > struct page {
> > union {
> > struct {/* Page cache and anonymous pages */
> > struct list_head lru;
> > ...
> > struct {/* slab, slob and slub */
> > union {
> > struct list_head slab_list; /* uses lru 
> > */
> > struct {/* Partial pages */
> > struct page *next;
> > 
> > slab_list and lru are in the same bits.  Once this patch set is in,
> > we can remove the enigmatic 'uses lru' comment that I added.
> 
> Ah, perfect, thanks! Makes total sense then.
> 
> Tobin, can you, please, add a note to the commit message?
> With the note:
> Reviewed-by: Roman Gushchin 

Awesome, thanks.  That's for all 4 patches or excluding 2?

thanks,
Tobin.


[PATCH 05/30] perf report: Parse time quantum

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Many workloads change over time. 'perf report' currently aggregates the
whole time range reported in perf.data.

This patch adds an option for a time quantum to quantisize the perf.data
over time.

This just adds the option, will be used in follow on patches for a time
sort key.

Signed-off-by: Andi Kleen 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: http://lkml.kernel.org/r/20190305144758.12397-6-a...@firstfloor.org
[ Use NSEC_PER_[MU]SEC ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-report.txt |  4 +++
 tools/perf/builtin-report.c  | 42 
 tools/perf/util/symbol.c |  2 ++
 tools/perf/util/symbol_conf.h|  1 +
 4 files changed, 49 insertions(+)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index 51dbc519dbce..9ec1702bccdd 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -497,6 +497,10 @@ include::itrace.txt[]
The period/hits keywords set the base the percentage is computed
on - the samples period or the number of samples (hits).
 
+--time-quantum::
+   Configure time quantum for time sort key. Default 100ms.
+   Accepts s, us, ms, ns units.
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 515864ba504a..05c8dd41106c 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -47,9 +47,11 @@
 #include 
 #include 
 #include 
+#include "sane_ctype.h"
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -926,6 +928,43 @@ report_parse_callchain_opt(const struct option *opt, const 
char *arg, int unset)
return parse_callchain_report_opt(arg);
 }
 
+static int
+parse_time_quantum(const struct option *opt, const char *arg,
+  int unset __maybe_unused)
+{
+   unsigned long *time_q = opt->value;
+   char *end;
+
+   *time_q = strtoul(arg, , 0);
+   if (end == arg)
+   goto parse_err;
+   if (*time_q == 0) {
+   pr_err("time quantum cannot be 0");
+   return -1;
+   }
+   while (isspace(*end))
+   end++;
+   if (*end == 0)
+   return 0;
+   if (!strcmp(end, "s")) {
+   *time_q *= NSEC_PER_SEC;
+   return 0;
+   }
+   if (!strcmp(end, "ms")) {
+   *time_q *= NSEC_PER_MSEC;
+   return 0;
+   }
+   if (!strcmp(end, "us")) {
+   *time_q *= NSEC_PER_USEC;
+   return 0;
+   }
+   if (!strcmp(end, "ns"))
+   return 0;
+parse_err:
+   pr_err("Cannot parse time quantum `%s'\n", arg);
+   return -1;
+}
+
 int
 report_parse_ignore_callees_opt(const struct option *opt __maybe_unused,
const char *arg, int unset __maybe_unused)
@@ -1148,6 +1187,9 @@ int cmd_report(int argc, const char **argv)
 "Set percent type local/global-period/hits",
 annotate_parse_percent_type),
OPT_BOOLEAN(0, "ns", _conf.nanosecs, "Show times in nanosecs"),
+   OPT_CALLBACK(0, "time-quantum", _conf.time_quantum, "time 
(ms|us|ns|s)",
+"Set time quantum for time sort key (default 100ms)",
+parse_time_quantum),
OPT_END()
};
struct perf_data data = {
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index eb873ea1c405..6b73a0eeb6a1 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -45,6 +46,7 @@ struct symbol_conf symbol_conf = {
.demangle   = true,
.demangle_kernel= false,
.cumulate_callchain = true,
+   .time_quantum   = 100 * NSEC_PER_MSEC, /* 100ms */
.show_hist_headers  = true,
.symfs  = "",
.event_group= true,
diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
index 095a297c8b47..a5684a71b78e 100644
--- a/tools/perf/util/symbol_conf.h
+++ b/tools/perf/util/symbol_conf.h
@@ -56,6 +56,7 @@ struct symbol_conf {
*sym_list_str,
*col_width_list_str,
*bt_stop_list_str;
+   unsigned long   time_quantum;
struct strlist  *dso_list,
*comm_list,
*sym_list,
-- 
2.20.1



[PATCH 03/30] perf report: Support output in nanoseconds

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Andi Kleen 

Upcoming changes add timestamp output in perf report. Add a --ns
argument similar to perf script to support nanoseconds resolution when
needed.

Signed-off-by: Andi Kleen 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: http://lkml.kernel.org/r/20190305144758.12397-5-a...@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-report.txt |  3 +++
 tools/perf/builtin-report.c  |  1 +
 tools/perf/builtin-script.c  | 11 +--
 tools/perf/util/symbol.c |  1 +
 tools/perf/util/symbol_conf.h|  1 +
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index 1a27bfe05039..51dbc519dbce 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -477,6 +477,9 @@ include::itrace.txt[]
Please note that not all mmaps are stored, options affecting which ones
are include 'perf record --data', for instance.
 
+--ns::
+   Show time stamps in nanoseconds.
+
 --stats::
Display overall events statistics without any further processing.
(like the one at the end of the perf report -D command)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index ee93c18a6685..515864ba504a 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1147,6 +1147,7 @@ int cmd_report(int argc, const char **argv)
OPT_CALLBACK(0, "percent-type", _opts, "local-period",
 "Set percent type local/global-period/hits",
 annotate_parse_percent_type),
+   OPT_BOOLEAN(0, "ns", _conf.nanosecs, "Show times in nanosecs"),
OPT_END()
};
struct perf_data data = {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index a5080afd361d..111787e83784 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -60,7 +60,6 @@ static bool   no_callchain;
 static boollatency_format;
 static boolsystem_wide;
 static boolprint_flags;
-static boolnanosecs;
 static const char  *cpu_list;
 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
 static struct perf_stat_config stat_config;
@@ -691,7 +690,7 @@ static int perf_sample__fprintf_start(struct perf_sample 
*sample,
secs = nsecs / NSEC_PER_SEC;
nsecs -= secs * NSEC_PER_SEC;
 
-   if (nanosecs)
+   if (symbol_conf.nanosecs)
printed += fprintf(fp, "%5lu.%09llu: ", secs, nsecs);
else {
char sample_time[32];
@@ -3244,7 +3243,7 @@ static int parse_insn_trace(const struct option *opt 
__maybe_unused,
 {
parse_output_fields(NULL, "+insn,-event,-period", 0);
itrace_parse_synth_opts(opt, "i0ns", 0);
-   nanosecs = true;
+   symbol_conf.nanosecs = true;
return 0;
 }
 
@@ -3262,7 +3261,7 @@ static int parse_call_trace(const struct option *opt 
__maybe_unused,
 {
parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0);
itrace_parse_synth_opts(opt, "cewp", 0);
-   nanosecs = true;
+   symbol_conf.nanosecs = true;
return 0;
 }
 
@@ -3272,7 +3271,7 @@ static int parse_callret_trace(const struct option *opt 
__maybe_unused,
 {
parse_output_fields(NULL, 
"-ip,-addr,-event,-period,+callindent,+flags", 0);
itrace_parse_synth_opts(opt, "crewp", 0);
-   nanosecs = true;
+   symbol_conf.nanosecs = true;
return 0;
 }
 
@@ -3408,7 +3407,7 @@ int cmd_script(int argc, const char **argv)
OPT_BOOLEAN('f', "force", _conf.force, "don't complain, do it"),
OPT_INTEGER(0, "max-blocks", _blocks,
"Maximum number of code blocks to dump with brstackinsn"),
-   OPT_BOOLEAN(0, "ns", ,
+   OPT_BOOLEAN(0, "ns", _conf.nanosecs,
"Use 9 decimal places when displaying time"),
OPT_CALLBACK_OPTARG(0, "itrace", _synth_opts, NULL, "opts",
"Instruction Tracing options\n" ITRACE_HELP,
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 758bf5f74e6e..eb873ea1c405 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -39,6 +39,7 @@ int vmlinux_path__nr_entries;
 char **vmlinux_path;
 
 struct symbol_conf symbol_conf = {
+   .nanosecs   = false,
.use_modules= true,
.try_vmlinux_path   = true,
.demangle   = true,
diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
index fffea68c1203..095a297c8b47 100644
--- a/tools/perf/util/symbol_conf.h
+++ b/tools/perf/util/symbol_conf.h
@@ -8,6 +8,7 @@ struct strlist;
 struct intlist;
 
 struct symbol_conf {
+   boolnanosecs;
unsigned short  

[PATCH 01/30] perf/core: Restore mmap record type correctly

2019-03-11 Thread Arnaldo Carvalho de Melo
From: Stephane Eranian 

On mmap(), perf_events generates a RECORD_MMAP record and then checks
which events are interested in this record. There are currently 2
versions of mmap records: RECORD_MMAP and RECORD_MMAP2. MMAP2 is larger.
The event configuration controls which version the user level tool
accepts.

If the event->attr.mmap2=1 field then MMAP2 record is returned.  The
perf_event_mmap_output() takes care of this. It checks attr->mmap2 and
corrects the record fields before putting it in the sampling buffer of
the event.  At the end the function restores the modified MMAP record
fields.

The problem is that the function restores the size but not the type.
Thus, if a subsequent event only accepts MMAP type, then it would
instead receive an MMAP2 record with a size of MMAP record.

This patch fixes the problem by restoring the record type on exit.

Signed-off-by: Stephane Eranian 
Acked-by: Peter Zijlstra (Intel) 
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Kan Liang 
Fixes: 13d7a2410fa6 ("perf: Add attr->mmap2 attribute to an event")
Link: http://lkml.kernel.org/r/20190307185233.225521-1-eran...@google.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 kernel/events/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 6fb27b564730..514b8e014a2d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7189,6 +7189,7 @@ static void perf_event_mmap_output(struct perf_event 
*event,
struct perf_output_handle handle;
struct perf_sample_data sample;
int size = mmap_event->event_id.header.size;
+   u32 type = mmap_event->event_id.header.type;
int ret;
 
if (!perf_event_mmap_match(event, data))
@@ -7232,6 +7233,7 @@ static void perf_event_mmap_output(struct perf_event 
*event,
perf_output_end();
 out:
mmap_event->event_id.header.size = size;
+   mmap_event->event_id.header.type = type;
 }
 
 static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
-- 
2.20.1



Re: [PATCH 1/1] of: reserved_mem: fix reserve memory leak

2019-03-11 Thread pierre kuo
hi Rob, Marek and Frank:
> > > The __reserved_mem_init_node will call region specific reserved memory
> > > init codes, but once all compatibled init codes failed, the memory region
> > > will left in memory.reserved and cause leakage.
> > >
> > > Take cma reserve memory DTS for example, if user declare 1MB size,
> > > which is not align to (PAGE_SIZE << max(MAX_ORDER - 1,
> > > pageblock_order)), rmem_cma_setup will return -EINVAL.
> > > Meanwhile, rmem_dma_setup will also return -EINVAL since "reusable"
> > > property is not set. If finally there is no reserved memory init pick up
> > > this memory, kernel will left the 1MB leak in memory.reserved.
> > >
> > > This patch will remove this kind of memory from memory.reserved, only
> > > when __reserved_mem_init_node return neither 0 nor -ENOENT.
> >
> > I'm not sure that un-reserving memory on error is the correct
> > behavior. It may be fine for something like CMA, but if it is some
> > shared memory used by another processor in the system not reserving it
> > would probably never be correct.
>
> In this patch, we un-reserving memory ONLY if explicit compatible matching 
> fail.
> That mean driver found something wrong while matching and let OS know.
> (But reserved-memory without compatible property will not be affected.)
>
> So per ur explaination, there would be cases that driver reported
> matching memory fail,
> but the memory is still needed by another processor?

Would you mind to give some comment and suggestion for this patch?
Sincerely appreciate ur kind help.


[v7 2/3] arm64: dts: lx2160a: add sata node support

2019-03-11 Thread Peng Ma
Add SATA device nodes for fsl-lx2160a and enable support
for QDS and RDB boards.

Signed-off-by: Peng Ma 
---
changed for V7:
- no changed

 arch/arm64/boot/dts/freescale/fsl-lx2160a-qds.dts |   16 +++
 arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts |   16 +++
 arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi|   44 +
 3 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/fsl-lx2160a-qds.dts 
b/arch/arm64/boot/dts/freescale/fsl-lx2160a-qds.dts
index 99a22ab..1a5acf6 100644
--- a/arch/arm64/boot/dts/freescale/fsl-lx2160a-qds.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-lx2160a-qds.dts
@@ -95,6 +95,22 @@
};
 };
 
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
  {
status = "okay";
 };
diff --git a/arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts 
b/arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts
index 6481e5f..5b6799e 100644
--- a/arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts
@@ -102,6 +102,22 @@
};
 };
 
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
  {
status = "okay";
 };
diff --git a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
index a79f5c1..592034b 100644
--- a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
@@ -671,6 +671,50 @@
status = "disabled";
};
 
+   sata0: sata@320 {
+   compatible = "fsl,lx2160a-ahci";
+   reg = <0x0 0x320 0x0 0x1>,
+ <0x7 0x100520 0x0 0x4>;
+   reg-names = "ahci", "sata-ecc";
+   interrupts = ;
+   clocks = < 4 3>;
+   dma-coherent;
+   status = "disabled";
+   };
+
+   sata1: sata@321 {
+   compatible = "fsl,lx2160a-ahci";
+   reg = <0x0 0x321 0x0 0x1>,
+ <0x7 0x100520 0x0 0x4>;
+   reg-names = "ahci", "sata-ecc";
+   interrupts = ;
+   clocks = < 4 3>;
+   dma-coherent;
+   status = "disabled";
+   };
+
+   sata2: sata@322 {
+   compatible = "fsl,lx2160a-ahci";
+   reg = <0x0 0x322 0x0 0x1>,
+ <0x7 0x100520 0x0 0x4>;
+   reg-names = "ahci", "sata-ecc";
+   interrupts = ;
+   clocks = < 4 3>;
+   dma-coherent;
+   status = "disabled";
+   };
+
+   sata3: sata@323 {
+   compatible = "fsl,lx2160a-ahci";
+   reg = <0x0 0x323 0x0 0x1>,
+ <0x7 0x100520 0x0 0x4>;
+   reg-names = "ahci", "sata-ecc";
+   interrupts = ;
+   clocks = < 4 3>;
+   dma-coherent;
+   status = "disabled";
+   };
+
smmu: iommu@500 {
compatible = "arm,mmu-500";
reg = <0 0x500 0 0x80>;
-- 
1.7.1



  1   2   3   4   5   6   7   8   9   10   >