1. 09 Mar, 2018 3 commits
    • Kan Liang's avatar
      perf/x86/intel: Fix event update for auto-reload · d31fc13f
      Kan Liang authored
      There is a bug when reading event->count with large PEBS enabled.
      
      Here is an example:
      
        # ./read_count
        0x71f0
        0x122c0
        0x1000000001c54
        0x100000001257d
        0x200000000bdc5
      
      In fixed period mode, the auto-reload mechanism could be enabled for
      PEBS events, but the calculation of event->count does not take the
      auto-reload values into account.
      
      Anyone who reads event->count will get the wrong result, e.g x86_pmu_read().
      
      This bug was introduced with the auto-reload mechanism enabled since
      commit:
      
        851559e3 ("perf/x86/intel: Use the PEBS auto reload mechanism when possible")
      
      Introduce intel_pmu_save_and_restart_reload() to calculate the
      event->count only for auto-reload.
      
      Since the counter increments a negative counter value and overflows on
      the sign switch, giving the interval:
      
              [-period, 0]
      
      the difference between two consequtive reads is:
      
       A) value2 - value1;
          when no overflows have happened in between,
       B) (0 - value1) + (value2 - (-period));
          when one overflow happened in between,
       C) (0 - value1) + (n - 1) * (period) + (value2 - (-period));
          when @n overflows happened in between.
      
      Here A) is the obvious difference, B) is the extension to the discrete
      interval, where the first term is to the top of the interval and the
      second term is from the bottom of the next interval and C) the extension
      to multiple intervals, where the middle term is the whole intervals
      covered.
      
      The equation for all cases is:
      
          value2 - value1 + n * period
      
      Previously the event->count is updated right before the sample output.
      But for case A, there is no PEBS record ready. It needs to be specially
      handled.
      
      Remove the auto-reload code from x86_perf_event_set_period() since
      we'll not longer call that function in this case.
      
      Based-on-code-from: Peter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Cc: acme@kernel.org
      Fixes: 851559e3 ("perf/x86/intel: Use the PEBS auto reload mechanism when possible")
      Link: http://lkml.kernel.org/r/1518474035-21006-2-git-send-email-kan.liang@linux.intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      d31fc13f
    • Kan Liang's avatar
      perf/x86/intel: Properly save/restore the PMU state in the NMI handler · 82d71ed0
      Kan Liang authored
      The PMU is disabled in intel_pmu_handle_irq(), but cpuc->enabled is not updated
      accordingly.
      
      This is fine in current usage because no-one checks it - but fix it
      for future code: for example, the drain_pebs() will be modified to
      fix an auto-reload bug.
      
      Properly save/restore the old PMU state.
      Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Cc: acme@kernel.org
      Cc: kernel test robot <fengguang.wu@intel.com>
      Link: http://lkml.kernel.org/r/6f44ee84-56f8-79f1-559b-08e371eaeb78@linux.intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
      82d71ed0
    • Kan Liang's avatar
      perf/x86/intel: Fix large period handling on Broadwell CPUs · f605cfca
      Kan Liang authored
      Large fixed period values could be truncated on Broadwell, for example:
      
        perf record -e cycles -c 10000000000
      
      Here the fixed period is 0x2540BE400, but the period which finally applied is
      0x540BE400 - which is wrong.
      
      The reason is that x86_pmu::limit_period() uses an u32 parameter, so the
      high 32 bits of 'period' get truncated.
      
      This bug was introduced in:
      
        commit 294fe0f5 ("perf/x86/intel: Add INST_RETIRED.ALL workarounds")
      
      It's safe to use u64 instead of u32:
      
       - Although the 'left' is s64, the value of 'left' must be positive when
         calling limit_period().
      
       - bdw_limit_period() only modifies the lowest 6 bits, it doesn't touch
         the higher 32 bits.
      Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vince Weaver <vincent.weaver@maine.edu>
      Fixes: 294fe0f5 ("perf/x86/intel: Add INST_RETIRED.ALL workarounds")
      Link: http://lkml.kernel.org/r/1519926894-3520-1-git-send-email-kan.liang@linux.intel.com
      [ Rewrote unacceptably bad changelog. ]
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      f605cfca
  2. 07 Mar, 2018 2 commits
  3. 06 Mar, 2018 5 commits
    • Adrian Hunter's avatar
      perf tools: Fix trigger class trigger_on() · de19e5c3
      Adrian Hunter authored
      trigger_on() means that the trigger is available but not ready, however
      trigger_on() was making it ready. That can segfault if the signal comes
      before trigger_ready(). e.g. (USR2 signal delivery not shown)
      
        $ perf record -e intel_pt//u -S sleep 1
        perf: Segmentation fault
        Obtained 16 stack frames.
        /home/ahunter/bin/perf(sighandler_dump_stack+0x40) [0x4ec550]
        /lib/x86_64-linux-gnu/libc.so.6(+0x36caf) [0x7fa76411acaf]
        /home/ahunter/bin/perf(perf_evsel__disable+0x26) [0x4b9dd6]
        /home/ahunter/bin/perf() [0x43a45b]
        /lib/x86_64-linux-gnu/libc.so.6(+0x36caf) [0x7fa76411acaf]
        /lib/x86_64-linux-gnu/libc.so.6(__xstat64+0x15) [0x7fa7641d2cc5]
        /home/ahunter/bin/perf() [0x4ec6c9]
        /home/ahunter/bin/perf() [0x4ec73b]
        /home/ahunter/bin/perf() [0x4ec73b]
        /home/ahunter/bin/perf() [0x4ec73b]
        /home/ahunter/bin/perf() [0x4eca15]
        /home/ahunter/bin/perf(machine__create_kernel_maps+0x257) [0x4f0b77]
        /home/ahunter/bin/perf(perf_session__new+0xc0) [0x4f86f0]
        /home/ahunter/bin/perf(cmd_record+0x722) [0x43c132]
        /home/ahunter/bin/perf() [0x4a11ae]
        /home/ahunter/bin/perf(main+0x5d4) [0x427fb4]
      
      Note, for testing purposes, this is hard to hit unless you add some sleep()
      in builtin-record.c before record__open().
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: stable@vger.kernel.org
      Fixes: 3dcc4436 ("perf tools: Introduce trigger class")
      Link: http://lkml.kernel.org/r/1519807144-30694-1-git-send-email-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      de19e5c3
    • Adrian Hunter's avatar
      perf auxtrace: Prevent decoding when --no-itrace · 2e2967f4
      Adrian Hunter authored
      Prevent auxtrace_queues__process_index() from queuing AUX area data for
      decoding when the --no-itrace option has been used.
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/1520327598-1317-3-git-send-email-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2e2967f4
    • Ilya Pronin's avatar
      perf stat: Fix CVS output format for non-supported counters · 40c21898
      Ilya Pronin authored
      When printing stats in CSV mode, 'perf stat' appends extra separators
      when a counter is not supported:
      
      <not supported>,,L1-dcache-store-misses,mesos/bd442f34-2b4a-47df-b966-9b281f9f56fc,0,100.00,,,,
      
      Which causes a failure when parsing fields. The numbers of separators
      should be the same for each line, no matter if the counter is or not
      supported.
      Signed-off-by: default avatarIlya Pronin <ipronin@twitter.com>
      Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Link: http://lkml.kernel.org/r/20180306064353.31930-1-xiyou.wangcong@gmail.com
      Fixes: 92a61f64 ("perf stat: Implement CSV metrics output")
      Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      40c21898
    • Ingo Molnar's avatar
      Merge tag 'perf-core-for-mingo-4.17-20180305' of... · 55b4ce61
      Ingo Molnar authored
      Merge tag 'perf-core-for-mingo-4.17-20180305' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
      
      Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:
      
      - Be more robust when drawing arrows in the annotation TUI, avoiding a
        segfault when jump instructions have as a target addresses in functions
        other that the one currently being annotated. The full fix will come in
        the following days, when jumping to other functions will work as call
        instructions (Arnaldo Carvalho de Melo)
      
      - Allow asking for the maximum allowed sample rate in 'top' and
        'record', i.e. 'perf record -F max' will read the
        kernel.perf_event_max_sample_rate sysctl and use it (Arnaldo Carvalho de Melo)
      
      - When the user specifies a freq above kernel.perf_event_max_sample_rate,
        Throttle it down to that max freq, and warn the user about it, add as
        well --strict-freq so that the previous behaviour of not starting the
        session when the desired freq can't be used can be selected (Arnaldo Carvalho de Melo)
      
      - Find 'call' instruction target symbol at parsing time, used so far in
        the TUI, part of the infrastructure changes that will end up allowing
        for jumps to navigate to other functions, just like 'call'
        instructions. (Arnaldo Carvalho de Melo)
      
      - Use xyarray dimensions to iterate fds in 'perf stat' (Andi Kleen)
      
      - Ignore threads for which the current user hasn't permissions when
        enabling system-wide --per-thread (Jin Yao)
      
      - Fix some backtrace perf test cases to use 'perf record' + 'perf script'
        instead, till 'perf trace' starts using ordered_events or equivalent
        to avoid symbol resolving artifacts due to reordering of
        PERF_RECORD_MMAP events (Jiri Olsa)
      
      - Fix crash in 'perf record' pipe mode, it needs to allocate the ID
        array even for a single event, unlike non-pipe mode (Jiri Olsa)
      
      - Make annoying fallback message on older kernels with newer 'perf top'
        binaries trying to use overwrite mode and that not being present
        in the older kernels (Kan Liang)
      
      - Switch last users of old APIs to the newer perf_mmap__read_event()
        one, then discard those old mmap read forward APIs (Kan Liang)
      
      - Fix the usage on the 'perf kallsyms' man page (Sangwon Hong)
      
      - Simplify cgroup arguments when tracking multiple events (weiping zhang)
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      55b4ce61
    • Ingo Molnar's avatar
      8af31363
  4. 05 Mar, 2018 29 commits
  5. 04 Mar, 2018 1 commit