簡體   English   中英

在 Linux 中,單獨的用戶空間/內核空間中的 Perf 指令/周期計數

[英]Perf instruction/cycles count in userspace/kernelspace alone in Linux

我正在嘗試使用 perf 分析具有用戶空間和內核空間代碼的應用程序。 我嘗試了啟用各種內核配置的所有其他可能性,但我無法單獨獲得用戶空間/內核空間中的指令/周期數。 我嘗試使用 ":u" 和 ":k 擴展指令和周期計數,但我得到的答復是

$ perf stat -e cycles:u,instructions:u ls

 Performance counter stats for 'ls':

   <not supported>      cycles:u

   <not supported>      instructions:u

       0.006047045 seconds time elapsed

       0.000000000 seconds user
       0.008098000 seconds sys

但是,僅針對循環/指令運行會給出如下所示的正確結果。

$ perf stat -e cycles,instructions ls

 Performance counter stats for 'ls':

          5362086      cycles
            528783      instructions              #    0.10  insn per cycle

       0.005487940 seconds time elapsed

       0.007800000 seconds user
       0.000000000 seconds sys

注意:這里 ls 只是作為一個例子來突出問題。

我正在運行 Linux 5.4 和 perf 版本 5.4.77.g1206eede9156。 而且,我在 ARM 板上運行上述命令。 下面是我在 Linux 內核中啟用的配置

CONFIG_PERF_EVENTS=y
CONFIG_PROFILING=y
CONFIG_TRACEPOINTS=y
CONFIG_KPROBES=y
CONFIG_OPTPROBES=y
CONFIG_KPROBES_ON_FTRACE=y
CONFIG_UPROBES=y
CONFIG_HAVE_KPROBES=y
CONFIG_HAVE_KRETPROBES=y
CONFIG_HAVE_OPTPROBES=y
CONFIG_HAVE_KPROBES_ON_FTRACE=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_DWARF4=y
CONFIG_FRAME_POINTER=y
CONFIG_FTRACE=y
CONFIG_KPROBE_EVENTS=y
CONFIG_UPROBE_EVENTS=y
CONFIG_PROBE_EVENTS=y

此外,命令行上的 perf list 列出了硬件/軟件事件等等

$ perf list
  branch-instructions OR branches                    [Hardware event]
  branch-misses                                      [Hardware event]
  cache-misses                                       [Hardware event]
  cache-references                                   [Hardware event]
  cpu-cycles OR cycles                               [Hardware event]
  instructions                                       [Hardware event]
  alignment-faults                                   [Software event]
  bpf-output                                         [Software event]
  context-switches OR cs                             [Software event]
  cpu-clock                                          [Software event]
  cpu-migrations OR migrations                       [Software event]
  dummy                                              [Software event]
  emulation-faults                                   [Software event]
  major-faults                                       [Software event]
  minor-faults                                       [Software event]
  page-faults OR faults                              [Software event]
  task-clock                                         [Software event]
  duration_time                                      [Tool event]
  L1-dcache-load-misses                              [Hardware cache event]
  L1-dcache-loads                                    [Hardware cache event]
  L1-dcache-prefetch-misses                          [Hardware cache event]
  L1-dcache-prefetches                               [Hardware cache event]
  L1-dcache-store-misses                             [Hardware cache event]
  L1-dcache-stores                                   [Hardware cache event]
  L1-icache-load-misses                              [Hardware cache event]
  L1-icache-loads                                    [Hardware cache event]
  L1-icache-prefetch-misses                          [Hardware cache event]
  L1-icache-prefetches                               [Hardware cache event]
  branch-load-misses                                 [Hardware cache event]
  branch-loads                                       [Hardware cache event]
  dTLB-load-misses                                   [Hardware cache event]
  dTLB-store-misses                                  [Hardware cache event]
  iTLB-load-misses                                   [Hardware cache event]

請建議如何解決此問題。 我做錯了什么嗎?

對我444,022 cycles:u444,022 cycles:u用於perf stat -e cycles:u ls perf 版本 5.13.g62fb9874f5da,在 Linux 5.12.15-arch1-1 上,在裸機 (x86-64 Skylake) 上, perf_event_paranoid=0
(使用現代 perf,您還可以使用perf stat --all-user暗示:u用於所有事件。)

我猜你的ARM CPU的硬件PERF專櫃不支持與權限級別的面具被編程,所以perf報告沒有能夠只計算用戶空間的指令的硬件計數器。

AFAIK,在每個中斷入口點都沒有鈎子來啟用/禁用硬件計數器; 僅計算內核、僅用戶或兩者,純粹是硬件功能。

硬件支持對於准確計數顯然是必不可少的,因為在軟件實現中,計數器仍然會計數,直到內核代碼運行保存當前計數。 (以及在恢復狀態之后,返回用戶空間之前的內核代碼。)此外,它會使每個中斷和系統調用更加昂貴,而不僅僅是通過在任務/線程之間的每個上下文切換中保存/恢復它們來虛擬化性能計數器。 因此,即使在沒有硬件支持特權掩碼的 CPU 上,內核也有充分的理由不支持在軟件中進行松散的嘗試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM