4

After I have done several reading on Hardware Performance Counter, I can claim that all of the Intel processors have supported with Hardware Performance Counter. So, In order to access these additional hardware registers ,i.e. hardware performance counters, I have used PAPI infrastructure frequently used to access and configure these counters.

When I used papi_avail utility program to report information about number hardware counters, unexpected value was viewed, i.e. with respect to Fig, number hardware counters : 0. Could it be?

With respect to my processors model (Intel core i7), I think this is incorrect value.

I really appreciate any help you can provide.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
M.Mrd
  • 41
  • 2

3 Answers3

2

If you need to know how many performance counters are supported by your Intel CPU, you can use the cpuid command (cf. man 1 cpuid).

It is quite verbose as it triggers the x86 cpuid instruction which returns many information on the processor. Among them, there are details about the Performance Monitoring Unit (PMU). By default, the command launches the cpuid instruction on all the CPU cores. But if the cores are identical you can limit the display to one core. For example, here is how we list the information on the first CPU:

$ cpuid -1
[...]
   Architecture Performance Monitoring Features (0xa/eax):
      version ID                               = 0x3 (3)
      number of counters per logical processor = 0x4 (4)
      bit width of counter                     = 0x30 (48)
      length of EBX bit vector                 = 0x7 (7)
   Architecture Performance Monitoring Features (0xa/ebx):
      core cycle event not available           = false
      instruction retired event not available  = false
      reference cycles event not available     = false
      last-level cache ref event not available = false
      last-level cache miss event not avail    = false
      branch inst retired event not available  = false
      branch mispred retired event not avail   = false
   Architecture Performance Monitoring Features (0xa/edx):
      number of fixed counters    = 0x3 (3)
      bit width of fixed counters = 0x30 (48)
      anythread deprecation       = false
[...]

In the above display, we can see that the PMU version is 3:

 version ID = 0x3 (3)

There are 4 programmable counters per core:

number of counters per logical processor = 0x4 (4)

There are 3 fixed counters per core:

number of fixed counters = 0x3 (3)

The counters are all 48 bits long:

bit width of counter        = 0x30 (48)
bit width of fixed counters = 0x30 (48)

The capabilities of the PMU are architecture specific. If you need additional details for your Intel PC/board, the first lines displayed by the previous command provide the CPU/architecture identification. For example:

   [...]
   vendor_id = "GenuineIntel"
   version information (1/eax):
      processor type  = primary processor (0)
      family          = 0x6 (6)
      model           = 0xa (10)
      stepping id     = 0x9 (9)
      extended family = 0x0 (0)
      extended model  = 0x3 (3)
      (family synth)  = 0x6 (6)
      (model synth)   = 0x3a (58)
      (simple synth)  = Intel Core (unknown type) (Ivy Bridge E1/N0/L1/P0) {Sandy Bridge}, 22nm
      [...]

With those information you can refer to the Intel documentation.

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
  • *it triggers the x86 cpuid instruction* - unfortunately not directly; it tries to read from `/dev/cpu/0/cpuid`, which requires a kernel driver to provide that interface. I guess that lets it make sure it reads CPUID info from each core separately, in case of a heterogeneous system? – Peter Cordes Oct 21 '20 at 23:56
  • @PeterCordes: cpuid accepts multiple options to use or not the cpuid driver. This driver needs not necessarily be loaded (and so, /dev/cpu/x/cpuid does not necessarily exists). For example, when used with -1 option, the program directly calls cpuid assembly instruction on the current cpu it is running on. A strace, on the command will not show any open(/dev/cpu/X/cpuid) with -1 option as cpuid assembly instruction is called. – Rachid K. Oct 22 '20 at 08:53
  • The version from `msr-tools` version `1.3-3` (Arch GNU/Linux) isn't like that. `strace cpuid -1` shows it failing to open `/dev/cpu/-1/cpuid`. I assume there's a different implementation that uses the same name, or there's a newer version; Arch hasn't updated the package since 2018. Ah, yeah it seems there's a `cpuid` *package* that presumably has a different command of the same name, in Arch's community-packaged stuff: https://aur.archlinux.org/packages/cpuid/ – Peter Cordes Oct 22 '20 at 09:05
  • Yes, on my Ubuntu system, the tool comes from the [cpuid package](https://launchpad.net/ubuntu/+source/cpuid/20200211-1) – Rachid K. Oct 22 '20 at 09:28
1

all what you need is to try:

sudo sh -c 'echo 1 >/proc/sys/kernel/perf_event_paranoid'

all recent Linux kernels are equipped with perf utility to access the hardware performance counters. However, for security issues, in default, we have no access to these counters. The default value stored in the file "perf_event_paranoid" is 3 means we can't access to the counters. By modifying the value to 1 (allow access), we can get information about available performance counters and can access them using perf or any available tools, like PAPI.

  • This would be a better answer if you explained *why* you should do that, and what it does. Also worth mentioning that Linux by default uses up one perf counter per core for an NMI watchdog, which you can also disable with sysctl `kernel/nmi_watchdog = 0` (i.e. `/proc/sys/kernel/nmi_watchdog`) – Peter Cordes Oct 02 '20 at 22:56
  • The provided answer was flagged for review as a Low Quality Post. Here are some guidelines for [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). This provided answer could benefit from an explanation. Code only answers are not considered "good" answers. From [Review](https://stackoverflow.com/review/low-quality-posts/27300417). – Trenton McKinney Oct 03 '20 at 04:02
  • why should i echo something, while i actually want to read some information, not write? – blaze9 Oct 21 '20 at 13:45
  • 1
    @blaze9: To change a kernel setting, allowing you to read the info you want without root privileges. Look at where the echo is being redirected. Or use `sysctl`. – Peter Cordes Oct 21 '20 at 23:53
0

Take a look at Chapters 18 "Performance Monitoring" and 19 "Performance-Monitoring Events" portion of the Intel® 64 and IA-32 Architectures Software Developer Manuals volume 3B (latest version here).

someneat
  • 348
  • 3
  • 9