1

I am using Linux perf tool to monitor system-wide (exclude_kernel == 0) PEBS samples. I was wondering whether PEBS sample can occur at interrupt context (i.e., during an interrupt is being served by the interrupt handler). If it is possible, is there any way to determine the context (e.g, process context, interrupt context) of the PEBS sample (i.e., register bits)?

Proy
  • 336
  • 2
  • 13

1 Answers1

0

PEBS sampling never occurs when an interrupt is being serviced. PEBS Data Store Save Area

PEBS uses the above buffering mechanism to store its records. You can clearly see all the PEBS relevant fields like PEBS buffer base and PEBS interrupt threshold etc. PEBS interrupts occur when the PEBS buffer index matches the PEBS interrupt threshold specified.

The PEBS interrupt handler will reset the PEBS Buffer Index back to the start of the PEBS buffer base. If PEBS sampling were to continue, then PEBS would also try to access the DS buffer to increment the PEBS Buffer Index. So both the PEBS Interrupt and PEBS itself will try to write to the same DS save area. This obviously points to a race condition between the PEBS interrupt handler and PEBS module.

To avoid this race condition, it is required to disable PEBS sampling (by disabling flags in the IA32_PEBS_ENABLE msr register). Also all the event counters must be disabled as well by the interrupt handler. This is the proof in the kernel.

However, if the PEBS interrupts cause too much throttling on the CPU, you can have a PERF_RECORD_THROTTLE event, but this is of course, not a PEBS_SAMPLE event but rather a PERF_RECORD event.

Arnabjyoti Kalita
  • 2,325
  • 1
  • 18
  • 31
  • From your comment, it seems that PEBS should be disabled when PEBS interrupt handler is being served. PEBS does not have any conflict with other interrupt handlers and can generate sample at interrupt context without race. Correct me if I am wrong. – Proy Dec 08 '17 at 18:17
  • PEBS will not have any conflicts with other interrupt handlers. As far as I know, the Data Store Save during PEBS will only be avoided during INIT, Processor Reset and when the system moves to SMM (System Management Mode) or ia-32 mode. – Arnabjyoti Kalita Dec 16 '17 at 03:53