···816816 if (ret)817817 return ret;818818819819+ if (event->attr.precise_ip &&820820+ (event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {821821+ /*822822+ * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P823823+ * (0x003c) so that we can use it with PEBS.824824+ *825825+ * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't826826+ * PEBS capable. However we can use INST_RETIRED.ANY_P827827+ * (0x00c0), which is a PEBS capable event, to get the same828828+ * count.829829+ *830830+ * INST_RETIRED.ANY_P counts the number of cycles that retires831831+ * CNTMASK instructions. By setting CNTMASK to a value (16)832832+ * larger than the maximum number of instructions that can be833833+ * retired per cycle (4) and then inverting the condition, we834834+ * count all cycles that retire 16 or less instructions, which835835+ * is every cycle.836836+ *837837+ * Thereby we gain a PEBS capable cycle counter.838838+ */839839+ u64 alt_config = 0x108000c0; /* INST_RETIRED.TOTAL_CYCLES */840840+841841+ alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);842842+ event->hw.config = alt_config;843843+ }844844+819845 if (event->attr.type != PERF_TYPE_RAW)820846 return 0;821847