perf_event_p6.c 3.4 KB

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