pmu.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #else /* CONFIG_CPU_HAS_PMU */
  51. #include <linux/err.h>
  52. static inline int
  53. reserve_pmu(enum arm_pmu_type type)
  54. {
  55. return -ENODEV;
  56. }
  57. static inline void
  58. release_pmu(enum arm_pmu_type type) { }
  59. #endif /* CONFIG_CPU_HAS_PMU */
  60. #ifdef CONFIG_HW_PERF_EVENTS
  61. /* The events for a given PMU register set. */
  62. struct pmu_hw_events {
  63. /*
  64. * The events that are active on the PMU for the given index.
  65. */
  66. struct perf_event **events;
  67. /*
  68. * A 1 bit for an index indicates that the counter is being used for
  69. * an event. A 0 means that the counter can be used.
  70. */
  71. unsigned long *used_mask;
  72. /*
  73. * Hardware lock to serialize accesses to PMU registers. Needed for the
  74. * read/modify/write sequences.
  75. */
  76. raw_spinlock_t pmu_lock;
  77. };
  78. struct arm_pmu {
  79. struct pmu pmu;
  80. enum arm_perf_pmu_ids id;
  81. enum arm_pmu_type type;
  82. cpumask_t active_irqs;
  83. const char *name;
  84. irqreturn_t (*handle_irq)(int irq_num, void *dev);
  85. void (*enable)(struct hw_perf_event *evt, int idx);
  86. void (*disable)(struct hw_perf_event *evt, int idx);
  87. int (*get_event_idx)(struct pmu_hw_events *hw_events,
  88. struct hw_perf_event *hwc);
  89. int (*set_event_filter)(struct hw_perf_event *evt,
  90. struct perf_event_attr *attr);
  91. u32 (*read_counter)(int idx);
  92. void (*write_counter)(int idx, u32 val);
  93. void (*start)(void);
  94. void (*stop)(void);
  95. void (*reset)(void *);
  96. int (*map_event)(struct perf_event *event);
  97. int num_events;
  98. atomic_t active_events;
  99. struct mutex reserve_mutex;
  100. u64 max_period;
  101. struct platform_device *plat_device;
  102. struct pmu_hw_events *(*get_hw_events)(void);
  103. };
  104. #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
  105. int __init armpmu_register(struct arm_pmu *armpmu, char *name, int type);
  106. u64 armpmu_event_update(struct perf_event *event,
  107. struct hw_perf_event *hwc,
  108. int idx, int overflow);
  109. int armpmu_event_set_period(struct perf_event *event,
  110. struct hw_perf_event *hwc,
  111. int idx);
  112. #endif /* CONFIG_HW_PERF_EVENTS */
  113. #endif /* __ARM_PMU_H__ */