perf_event_p6.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include <linux/perf_event.h>
  2. #include <linux/types.h>
  3. #include "perf_event.h"
  4. /*
  5. * Not sure about some of these
  6. */
  7. static const u64 p6_perfmon_event_map[] =
  8. {
  9. [PERF_COUNT_HW_CPU_CYCLES] = 0x0079,
  10. [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0,
  11. [PERF_COUNT_HW_CACHE_REFERENCES] = 0x0f2e,
  12. [PERF_COUNT_HW_CACHE_MISSES] = 0x012e,
  13. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c4,
  14. [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c5,
  15. [PERF_COUNT_HW_BUS_CYCLES] = 0x0062,
  16. };
  17. static u64 p6_pmu_event_map(int hw_event)
  18. {
  19. return p6_perfmon_event_map[hw_event];
  20. }
  21. /*
  22. * Event setting that is specified not to count anything.
  23. * We use this to effectively disable a counter.
  24. *
  25. * L2_RQSTS with 0 MESI unit mask.
  26. */
  27. #define P6_NOP_EVENT 0x0000002EULL
  28. static struct event_constraint p6_event_constraints[] =
  29. {
  30. INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FLOPS */
  31. INTEL_EVENT_CONSTRAINT(0x10, 0x1), /* FP_COMP_OPS_EXE */
  32. INTEL_EVENT_CONSTRAINT(0x11, 0x1), /* FP_ASSIST */
  33. INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */
  34. INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */
  35. INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */
  36. EVENT_CONSTRAINT_END
  37. };
  38. static void p6_pmu_disable_all(void)
  39. {
  40. u64 val;
  41. /* p6 only has one enable register */
  42. rdmsrl(MSR_P6_EVNTSEL0, val);
  43. val &= ~ARCH_PERFMON_EVENTSEL_ENABLE;
  44. wrmsrl(MSR_P6_EVNTSEL0, val);
  45. }
  46. static void p6_pmu_enable_all(int added)
  47. {
  48. unsigned long val;
  49. /* p6 only has one enable register */
  50. rdmsrl(MSR_P6_EVNTSEL0, val);
  51. val |= ARCH_PERFMON_EVENTSEL_ENABLE;
  52. wrmsrl(MSR_P6_EVNTSEL0, val);
  53. }
  54. static inline void
  55. p6_pmu_disable_event(struct perf_event *event)
  56. {
  57. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  58. struct hw_perf_event *hwc = &event->hw;
  59. u64 val = P6_NOP_EVENT;
  60. if (cpuc->enabled)
  61. val |= ARCH_PERFMON_EVENTSEL_ENABLE;
  62. (void)checking_wrmsrl(hwc->config_base, val);
  63. }
  64. static void p6_pmu_enable_event(struct perf_event *event)
  65. {
  66. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  67. struct hw_perf_event *hwc = &event->hw;
  68. u64 val;
  69. val = hwc->config;
  70. if (cpuc->enabled)
  71. val |= ARCH_PERFMON_EVENTSEL_ENABLE;
  72. (void)checking_wrmsrl(hwc->config_base, val);
  73. }
  74. PMU_FORMAT_ATTR(event, "config:0-7" );
  75. PMU_FORMAT_ATTR(umask, "config:8-15" );
  76. PMU_FORMAT_ATTR(edge, "config:18" );
  77. PMU_FORMAT_ATTR(pc, "config:19" );
  78. PMU_FORMAT_ATTR(inv, "config:23" );
  79. PMU_FORMAT_ATTR(cmask, "config:24-31" );
  80. static struct attribute *intel_p6_formats_attr[] = {
  81. &format_attr_event.attr,
  82. &format_attr_umask.attr,
  83. &format_attr_edge.attr,
  84. &format_attr_pc.attr,
  85. &format_attr_inv.attr,
  86. &format_attr_cmask.attr,
  87. NULL,
  88. };
  89. static __initconst const struct x86_pmu p6_pmu = {
  90. .name = "p6",
  91. .handle_irq = x86_pmu_handle_irq,
  92. .disable_all = p6_pmu_disable_all,
  93. .enable_all = p6_pmu_enable_all,
  94. .enable = p6_pmu_enable_event,
  95. .disable = p6_pmu_disable_event,
  96. .hw_config = x86_pmu_hw_config,
  97. .schedule_events = x86_schedule_events,
  98. .eventsel = MSR_P6_EVNTSEL0,
  99. .perfctr = MSR_P6_PERFCTR0,
  100. .event_map = p6_pmu_event_map,
  101. .max_events = ARRAY_SIZE(p6_perfmon_event_map),
  102. .apic = 1,
  103. .max_period = (1ULL << 31) - 1,
  104. .version = 0,
  105. .num_counters = 2,
  106. /*
  107. * Events have 40 bits implemented. However they are designed such
  108. * that bits [32-39] are sign extensions of bit 31. As such the
  109. * effective width of a event for P6-like PMU is 32 bits only.
  110. *
  111. * See IA-32 Intel Architecture Software developer manual Vol 3B
  112. */
  113. .cntval_bits = 32,
  114. .cntval_mask = (1ULL << 32) - 1,
  115. .get_event_constraints = x86_get_event_constraints,
  116. .event_constraints = p6_event_constraints,
  117. .format_attrs = intel_p6_formats_attr,
  118. };
  119. __init int p6_pmu_init(void)
  120. {
  121. switch (boot_cpu_data.x86_model) {
  122. case 1:
  123. case 3: /* Pentium Pro */
  124. case 5:
  125. case 6: /* Pentium II */
  126. case 7:
  127. case 8:
  128. case 11: /* Pentium III */
  129. case 9:
  130. case 13:
  131. /* Pentium M */
  132. break;
  133. default:
  134. pr_cont("unsupported p6 CPU model %d ",
  135. boot_cpu_data.x86_model);
  136. return -ENODEV;
  137. }
  138. x86_pmu = p6_pmu;
  139. return 0;
  140. }