pmu.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * linux/arch/arm/include/asm/pmu.h
  3. *
  4. * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #ifndef __ARM_PMU_H__
  12. #define __ARM_PMU_H__
  13. #include <linux/interrupt.h>
  14. #include <linux/perf_event.h>
  15. /*
  16. * Types of PMUs that can be accessed directly and require mutual
  17. * exclusion between profiling tools.
  18. */
  19. enum arm_pmu_type {
  20. ARM_PMU_DEVICE_CPU = 0,
  21. ARM_NUM_PMU_DEVICES,
  22. };
  23. /*
  24. * struct arm_pmu_platdata - ARM PMU platform data
  25. *
  26. * @handle_irq: an optional handler which will be called from the interrupt and
  27. * passed the address of the low level handler, and can be used to implement
  28. * any platform specific handling before or after calling it.
  29. */
  30. struct arm_pmu_platdata {
  31. irqreturn_t (*handle_irq)(int irq, void *dev,
  32. irq_handler_t pmu_handler);
  33. };
  34. #ifdef CONFIG_CPU_HAS_PMU
  35. /**
  36. * reserve_pmu() - reserve the hardware performance counters
  37. *
  38. * Reserve the hardware performance counters in the system for exclusive use.
  39. * Returns 0 on success or -EBUSY if the lock is already held.
  40. */
  41. extern int
  42. reserve_pmu(enum arm_pmu_type type);
  43. /**
  44. * release_pmu() - Relinquish control of the performance counters
  45. *
  46. * Release the performance counters and allow someone else to use them.
  47. */
  48. extern void
  49. release_pmu(enum arm_pmu_type type);
  50. /**
  51. * init_pmu() - Initialise the PMU.
  52. *
  53. * Initialise the system ready for PMU enabling. This should typically set the
  54. * IRQ affinity and nothing else. The users (oprofile/perf events etc) will do
  55. * the actual hardware initialisation.
  56. */
  57. extern int
  58. init_pmu(enum arm_pmu_type type);
  59. #else /* CONFIG_CPU_HAS_PMU */
  60. #include <linux/err.h>
  61. static inline int
  62. reserve_pmu(enum arm_pmu_type type)
  63. {
  64. return -ENODEV;
  65. }
  66. static inline void
  67. release_pmu(enum arm_pmu_type type) { }
  68. #endif /* CONFIG_CPU_HAS_PMU */
  69. #ifdef CONFIG_HW_PERF_EVENTS
  70. /* The events for a given PMU register set. */
  71. struct pmu_hw_events {
  72. /*
  73. * The events that are active on the PMU for the given index.
  74. */
  75. struct perf_event **events;
  76. /*
  77. * A 1 bit for an index indicates that the counter is being used for
  78. * an event. A 0 means that the counter can be used.
  79. */
  80. unsigned long *used_mask;
  81. /*
  82. * Hardware lock to serialize accesses to PMU registers. Needed for the
  83. * read/modify/write sequences.
  84. */
  85. raw_spinlock_t pmu_lock;
  86. };
  87. struct arm_pmu {
  88. struct pmu pmu;
  89. enum arm_perf_pmu_ids id;
  90. enum arm_pmu_type type;
  91. cpumask_t active_irqs;
  92. const char *name;
  93. irqreturn_t (*handle_irq)(int irq_num, void *dev);
  94. void (*enable)(struct hw_perf_event *evt, int idx);
  95. void (*disable)(struct hw_perf_event *evt, int idx);
  96. int (*get_event_idx)(struct pmu_hw_events *hw_events,
  97. struct hw_perf_event *hwc);
  98. int (*set_event_filter)(struct hw_perf_event *evt,
  99. struct perf_event_attr *attr);
  100. u32 (*read_counter)(int idx);
  101. void (*write_counter)(int idx, u32 val);
  102. void (*start)(void);
  103. void (*stop)(void);
  104. void (*reset)(void *);
  105. int (*map_event)(struct perf_event *event);
  106. int num_events;
  107. atomic_t active_events;
  108. struct mutex reserve_mutex;
  109. u64 max_period;
  110. struct platform_device *plat_device;
  111. struct pmu_hw_events *(*get_hw_events)(void);
  112. };
  113. #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
  114. int __init armpmu_register(struct arm_pmu *armpmu, char *name, int type);
  115. u64 armpmu_event_update(struct perf_event *event,
  116. struct hw_perf_event *hwc,
  117. int idx, int overflow);
  118. int armpmu_event_set_period(struct perf_event *event,
  119. struct hw_perf_event *hwc,
  120. int idx);
  121. #endif /* CONFIG_HW_PERF_EVENTS */
  122. #endif /* __ARM_PMU_H__ */