perf_event_p6.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. static __initconst const struct x86_pmu p6_pmu = {
  75. .name = "p6",
  76. .handle_irq = x86_pmu_handle_irq,
  77. .disable_all = p6_pmu_disable_all,
  78. .enable_all = p6_pmu_enable_all,
  79. .enable = p6_pmu_enable_event,
  80. .disable = p6_pmu_disable_event,
  81. .hw_config = x86_pmu_hw_config,
  82. .schedule_events = x86_schedule_events,
  83. .eventsel = MSR_P6_EVNTSEL0,
  84. .perfctr = MSR_P6_PERFCTR0,
  85. .event_map = p6_pmu_event_map,
  86. .max_events = ARRAY_SIZE(p6_perfmon_event_map),
  87. .apic = 1,
  88. .max_period = (1ULL << 31) - 1,
  89. .version = 0,
  90. .num_counters = 2,
  91. /*
  92. * Events have 40 bits implemented. However they are designed such
  93. * that bits [32-39] are sign extensions of bit 31. As such the
  94. * effective width of a event for P6-like PMU is 32 bits only.
  95. *
  96. * See IA-32 Intel Architecture Software developer manual Vol 3B
  97. */
  98. .cntval_bits = 32,
  99. .cntval_mask = (1ULL << 32) - 1,
  100. .get_event_constraints = x86_get_event_constraints,
  101. .event_constraints = p6_event_constraints,
  102. };
  103. __init int p6_pmu_init(void)
  104. {
  105. switch (boot_cpu_data.x86_model) {
  106. case 1:
  107. case 3: /* Pentium Pro */
  108. case 5:
  109. case 6: /* Pentium II */
  110. case 7:
  111. case 8:
  112. case 11: /* Pentium III */
  113. case 9:
  114. case 13:
  115. /* Pentium M */
  116. break;
  117. default:
  118. pr_cont("unsupported p6 CPU model %d ",
  119. boot_cpu_data.x86_model);
  120. return -ENODEV;
  121. }
  122. x86_pmu = p6_pmu;
  123. return 0;
  124. }