1. 03 Oct, 2016 7 commits
    • Sukadev Bhattiprolu's avatar
      perf pmu: Use pmu_events table to create aliases · 933f82ff
      Sukadev Bhattiprolu authored
      At run time (when 'perf' is starting up), locate the specific table of
      PMU events that corresponds to the current CPU. Using that table, create
      aliases for the each of the PMU events in the CPU. The use these aliases
      to parse the user specified perf event.
      
      In short this would allow the user to specify events using their aliases
      rather than raw event codes.
      
      Based on input and some earlier patches from Andi Kleen, Jiri Olsa.
      Signed-off-by: default avatarSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Acked-by: default avatarIngo Molnar <mingo@kernel.org>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: http://lkml.kernel.org/r/1473978296-20712-4-git-send-email-sukadev@linux.vnet.ibm.com
      [ Make pmu_add_cpu_aliases() return void, since it was returning just '0' and
        furthermore, even that was being discarded via an explicit (void) cast ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      933f82ff
    • Andi Kleen's avatar
      perf jevents: Program to convert JSON file · 80eeb67f
      Andi Kleen authored
      This is a modified version of an earlier patch by Andi Kleen.
      
      We expect architectures to create JSON files describing the performance
      monitoring (PMU) events that each CPU model/family of the architecture
      supports.
      
      Following is an example of the JSON file entry for an x86 event:
      
          	[
          	...
          	{
          	"EventCode": "0x00",
          	"UMask": "0x01",
          	"EventName": "INST_RETIRED.ANY",
          	"BriefDescription": "Instructions retired from execution.",
          	"PublicDescription": "Instructions retired from execution.",
          	"Counter": "Fixed counter 1",
          	"CounterHTOff": "Fixed counter 1",
          	"SampleAfterValue": "2000003",
          	"SampleAfterValue": "2000003",
          	"MSRIndex": "0",
          	"MSRValue": "0",
          	"TakenAlone": "0",
          	"CounterMask": "0",
          	"Invert": "0",
          	"AnyThread": "0",
          	"EdgeDetect": "0",
          	"PEBS": "0",
          	"PRECISE_STORE": "0",
          	"Errata": "null",
          	"Offcore": "0"
          	},
          	...
      
          	]
      
      All the PMU events supported by a CPU model/family must be grouped into
      "topics" such as "Pipelining", "Floating-point", "Virtual-memory" etc.
      
      All events belonging to a topic must be placed in a separate JSON file
      (eg: "Pipelining.json") and all the topic JSON files for a CPU model must
      be in a separate directory.
      
      	Eg: for the CPU model "Silvermont_core":
      
          	$ ls tools/perf/pmu-events/arch/x86/Silvermont_core
          	Floating-point.json
          	Memory.json
          	Other.json
          	Pipelining.json
          	Virtualmemory.json
      
      Finally, to allow multiple CPU models to share a single set of JSON files,
      architectures must provide a mapping between a model and its set of events:
      
          	$ grep Silvermont tools/perf/pmu-events/arch/x86/mapfile.csv
          	GenuineIntel-6-4D,V13,Silvermont_core,core
          	GenuineIntel-6-4C,V13,Silvermont_core,core
      
      which maps each CPU, identified by [vendor, family, model, version, type]
      to a directory of JSON files. Thus two (or more) CPU models support the
      set of PMU events listed in the directory.
      
          	tools/perf/pmu-events/arch/x86/Silvermont_core/
      
      Given this organization of files, the program, jevents:
      
      	- locates all JSON files for each CPU-model of the architecture,
      
      	- parses all JSON files for the CPU-model and generates a C-style
      	  "PMU-events table" (pmu-events.c) for the model
      
      	- locates a mapfile for the architecture
      
      	- builds a global table, mapping each model of CPU to the corresponding
      	  PMU-events table.
      
      The 'pmu-events.c' is generated when building perf and added to libperf.a.
      The global table pmu_events_map[] table in this pmu-events.c will be used
      in perf in a follow-on patch.
      
      If the architecture does not have any JSON files or there is an error in
      processing them, an empty mapping file is created. This would allow the
      build of perf to proceed even if we are not able to provide aliases for
      events.
      
      The parser for JSON files allows parsing Intel style JSON event files. This
      allows to use an Intel event list directly with perf. The Intel event lists
      can be quite large and are too big to store in unswappable kernel memory.
      
      The conversion from JSON to C-style is straight forward.  The parser knows
      (very little) Intel specific information, and can be easily extended to
      handle fields for other CPUs.
      
      The parser code is partially shared with an independent parsing library,
      which is 2-clause BSD licensed. To avoid any conflicts I marked those
      files as BSD licensed too. As part of perf they become GPLv2.
      
      Committer notes:
      
      Fixes:
      
      1) Limit maxfds to 512 to avoid nftd() segfaulting on alloca() with a
         big rlim_max, as in docker containers - acme
      
      2) Make jevents a hostprog, supporting cross compilation - jolsa
      
      3) Use HOSTCC for jevents final step - acme
      
      4) Define _GNU_SOURCE for asprintf, as we can't use CC's EXTRA_CFLAGS,
        that has to have --sysroot on the Android NDK 24 - acme
      
      5) Removed $(srctree)/tools/perf/pmu-events/pmu-events.c from the
         'clean' target, it is generated on $(OUTPUT)pmu-events/pmu-events.c,
         which is already taken care of in the original patch - acme
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
      Signed-off-by: default avatarSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Acked-by: default avatarIngo Molnar <mingo@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: http://lkml.kernel.org/r/1473978296-20712-3-git-send-email-sukadev@linux.vnet.ibm.com
      Link: http://lkml.kernel.org/r/20160927141846.GA6589@kravaSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      80eeb67f
    • Andi Kleen's avatar
      perf tools: Add jsmn `jasmine' JSON parser · 867a979a
      Andi Kleen authored
      I need a JSON parser. This adds the simplest JSON parser I could find --
      Serge Zaitsev's jsmn `jasmine' -- to the perf library. I merely
      converted it to (mostly) Linux style and added support for non 0
      terminated input.
      
      The parser is quite straight forward and does not copy any data, just
      returns tokens with offsets into the input buffer. So it's relatively
      efficient and simple to use.
      
      The code is not fully checkpatch clean, but I didn't want to completely
      fork the upstream code.
      
      Original source: http://zserge.bitbucket.org/jsmn.html
      
      In addition I added a simple wrapper that mmaps a json file and provides
      some straight forward access functions.
      
      Used in follow-on patches to parse event files.
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Acked-by: default avatarIngo Molnar <mingo@kernel.org>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: http://lkml.kernel.org/r/1473978296-20712-2-git-send-email-sukadev@linux.vnet.ibm.comSigned-off-by: default avatarSukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      [ Use fcntl.h instead of sys/fcntl.h to fix the build on Alpine Linux 3.4/musl libc,
        use stdbool.h to avoid clashing with 'bool' typedef there ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      867a979a
    • Jiri Olsa's avatar
      tools build: Make fixdep a hostprog · 6b3db6f9
      Jiri Olsa authored
      It is used in the build process, so stop suppressing its build in tools
      cross builds.
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Andi Kleen <andi@firstfloor.org>
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: http://lkml.kernel.org/r/20160927141846.GA6589@krava
      [ Use HOSTCC on the $(OUTPUT)fixdep target, it was using the x-compiler
        to link fixdep-in.o, that was correctly built with HOSTCC and thus failing ]
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6b3db6f9
    • Jiri Olsa's avatar
      tools build: Add support for host programs format · 0c3b7e42
      Jiri Olsa authored
      In some cases, like for fixdep and shortly for jevents, we need to build a tool
      to run on the host that will be used in building a tool, such as perf, that is
      being cross compiled, so do like the kernel and provide HOSTCC, HOSTLD and HOSTAR
      to do that.
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Requested-by: default avatarAndi Kleen <andi@firstfloor.org>
      Requested-and-Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: http://lkml.kernel.org/r/20160927141846.GA6589@kravaSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      0c3b7e42
    • Arnaldo Carvalho de Melo's avatar
      perf tools: Experiment with cppcheck · 18ef15c6
      Arnaldo Carvalho de Melo authored
      Experimenting a bit using cppcheck[1], a static checker brought to my
      attention by Colin, reducing the scope of some variables, reducing the
      line of source code lines in the process:
      
        $ cppcheck --enable=style tools/perf/util/thread.c
        Checking tools/perf/util/thread.c...
        [tools/perf/util/thread.c:17]: (style) The scope of the variable 'leader' can be reduced.
        [tools/perf/util/thread.c:133]: (style) The scope of the variable 'err' can be reduced.
        [tools/perf/util/thread.c:273]: (style) The scope of the variable 'err' can be reduced.
      
      Will continue later, but these are already useful, keep them.
      
      1: https://sourceforge.net/p/cppcheck/wiki/Home/
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Colin Ian King <colin.king@canonical.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-ixws7lbycihhpmq9cc949ti6@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      18ef15c6
    • Colin Ian King's avatar
      perf probe: Check if *ptr2 is zero and not ptr2 · ead1a574
      Colin Ian King authored
      Static anaylsis with cppcheck[1] detected an incorrect comparison:
      [tools/perf/util/probe-event.c:216]: (warning) Char literal compared
      with pointer 'ptr2'. Did you intend to dereference it?
      
      Dereference ptr2 for the comparison to fix this.
      
      1: https://sourceforge.net/p/cppcheck/wiki/Home/Signed-off-by: default avatarColin King <colin.king@canonical.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Fixes: 35726d3a ("perf probe: Fix to cut off incompatible chars from group name")
      Link: http://lkml.kernel.org/r/20161003103431.18534-1-colin.king@canonical.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ead1a574
  2. 29 Sep, 2016 24 commits
  3. 28 Sep, 2016 3 commits
    • Arnaldo Carvalho de Melo's avatar
      perf trace: Beautify sched_[gs]et_attr return value · f0bbd602
      Arnaldo Carvalho de Melo authored
      Both return errno, show the string associated then.
      
      More work needed to capture the sched_attr arg to beautify it in turn,
      probably using BPF.
      
      Before:
      
           0.210 ( 0.001 ms): sched_setattr(uattr: 0x7ffc684f02b0) = -22
      
      After the patch, for this sched_attr, all other parms are zero, so not
      shown:
      
              struct sched_attr attr = {
                      .size           = sizeof(attr),
                      .sched_policy   = SCHED_DEADLINE,
                      .sched_runtime  = 10 * USECS_PER_SEC,
                      .sched_period   = 30 * USECS_PER_SEC,
                      .sched_deadline = attr.sched_period,
              };
      
           0.321 ( 0.002 ms): sched_setattr(uattr: 0x7ffc44116da0) = -1 EINVAL Invalid argument
      
        [root@jouet c]# perf trace -e sched_setattr ./sched_deadline
        Couldn't negotiate deadline: Invalid argument
           0.229 ( 0.003 ms): sched_setattr(uattr: 0x7ffd8dcd8df0) = -1 EINVAL Invalid argument
        [root@jouet c]#
      
      Now to figure out the reason for this EINVAL.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Clark Williams <williams@redhat.com>
      Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-tyot2n7e48zm8pdw8tbcm3sl@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f0bbd602
    • Wang Nan's avatar
      perf data: Fix building in 32 bit platform with libbabeltrace · f2c8852e
      Wang Nan authored
      On ARM32 building it report following error when we build with
      libbabeltrace:
      
        util/data-convert-bt.c: In function 'add_bpf_output_values':
        util/data-convert-bt.c:440:3: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'unsigned int' [-Werror=format]
        cc1: all warnings being treated as errors
      
      Fix it by changing %lu to %zu.
      Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Zefan Li <lizefan@huawei.com>
      Cc: pi3orama@163.com
      Fixes: 6122d57e ("perf data: Support converting data from bpf_perf_event_output()")
      Link: http://lkml.kernel.org/r/1475035126-146587-1-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f2c8852e
    • Adrian Hunter's avatar
      perf tools: Fix MMAP event synthesis broken by MAP_HUGETLB change · 973186ca
      Adrian Hunter authored
      Patch "perf record: Mark MAP_HUGETLB when synthesizing mmap events") breaks
      MMAP event synthesis.  The executable name comparison will match any name
      if the length is zero, resulting in all the user space maps becoming
      anonymous.  This is particularly noticeable with system-wide traces.
      Example:
      
      	perf record -a sleep 1
      	perf script --show-mmap-events
      
      Committer note:
      
      That is not the case when, say, one has a qemu instance and libvirt actually
      mounts hugetlbfs. To test this I had to first umount it:
      
      [root@jouet ~]# mount | grep hugetlbfs
      hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
      [root@jouet ~]#
      
      After unmount it the error fixed by this patch manifests itself:
      
        # perf record -a sleep 1
        # perf script --show-mmap-events | grep PERF_RECORD_MMAP2 | head -5
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x557d47ed8000(0x167000) @ 0 fd:00 3146896 7362875424355726126]: r-xp //anon
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c488d000(0x4000) @ 0 fd:00 3153214 7362875424355726126]: r-xp //anon
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c4a92000(0x3d000) @ 0 fd:00 3159276 7362875424355726126]: r-xp //anon
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c4cd5000(0x15000) @ 0 fd:00 3153725 7362875424355726126]: r-xp //anon
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c4eeb000(0x25000) @ 0 fd:00 3153260 7362875424355726126]: r-xp //anon
        #
      
      Fixed version:
      
        # perf record -a sleep 1
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 1.419 MB perf.data (182 samples) ]
        # perf script --show-mmap-events | grep PERF_RECORD_MMAP2 | head -5
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x557d47ed8000(0x167000) @ 0 fd:00 3146896 7362875424355726126]: r-xp /usr/lib/systemd/systemd
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c488d000(0x4000) @ 0 fd:00 3153214 7362875424355726126]: r-xp /usr/lib64/libuuid.so.1.3.0
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c4a92000(0x3d000) @ 0 fd:00 3159276 7362875424355726126]: r-xp /usr/lib64/libblkid.so.1.1.0
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c4cd5000(0x15000) @ 0 fd:00 3153725 7362875424355726126]: r-xp /usr/lib64/libz.so.1.2.8
          systemd 0 [000] 0.000000: PERF_RECORD_MMAP2 1/1: [0x7f96c4eeb000(0x25000) @ 0 fd:00 3153260 7362875424355726126]: r-xp /usr/lib64/liblzma.so.5.2.2
      [root@jouet ~]#
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Link: http://lkml.kernel.org/r/1474641528-18776-3-git-send-email-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      973186ca
  4. 27 Sep, 2016 1 commit
  5. 23 Sep, 2016 2 commits
  6. 22 Sep, 2016 3 commits