pmu.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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
  27. * interrupt and passed the address of the low level handler,
  28. * and can be used to implement any platform specific handling
  29. * before or after calling it.
  30. * @enable_irq: an optional handler which will be called after
  31. * request_irq and be used to handle some platform specific
  32. * irq enablement
  33. * @disable_irq: an optional handler which will be called before
  34. * free_irq and be used to handle some platform specific
  35. * irq disablement
  36. */
  37. struct arm_pmu_platdata {
  38. irqreturn_t (*handle_irq)(int irq, void *dev,
  39. irq_handler_t pmu_handler);
  40. void (*enable_irq)(int irq);
  41. void (*disable_irq)(int irq);
  42. };
  43. #ifdef CONFIG_CPU_HAS_PMU
  44. /**
  45. * reserve_pmu() - reserve the hardware performance counters
  46. *
  47. * Reserve the hardware performance counters in the system for exclusive use.
  48. * Returns 0 on success or -EBUSY if the lock is already held.
  49. */
  50. extern int
  51. reserve_pmu(enum arm_pmu_type type);
  52. /**
  53. * release_pmu() - Relinquish control of the performance counters
  54. *
  55. * Release the performance counters and allow someone else to use them.
  56. */
  57. extern void
  58. release_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);
  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__ */