branch.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef _PERF_BRANCH_H
  2. #define _PERF_BRANCH_H 1
  3. /*
  4. * The linux/stddef.h isn't need here, but is needed for __always_inline used
  5. * in files included from uapi/linux/perf_event.h such as
  6. * /usr/include/linux/swab.h and /usr/include/linux/byteorder/little_endian.h,
  7. * detected in at least musl libc, used in Alpine Linux. -acme
  8. */
  9. #include <stdio.h>
  10. #include <stdint.h>
  11. #include <linux/compiler.h>
  12. #include <linux/stddef.h>
  13. #include <linux/perf_event.h>
  14. #include <linux/types.h>
  15. #include "event.h"
  16. struct branch_flags {
  17. union {
  18. u64 value;
  19. struct {
  20. u64 mispred:1;
  21. u64 predicted:1;
  22. u64 in_tx:1;
  23. u64 abort:1;
  24. u64 cycles:16;
  25. u64 type:4;
  26. u64 reserved:40;
  27. };
  28. };
  29. };
  30. struct branch_info {
  31. struct addr_map_symbol from;
  32. struct addr_map_symbol to;
  33. struct branch_flags flags;
  34. char *srcline_from;
  35. char *srcline_to;
  36. };
  37. struct branch_entry {
  38. u64 from;
  39. u64 to;
  40. struct branch_flags flags;
  41. };
  42. struct branch_stack {
  43. u64 nr;
  44. u64 hw_idx;
  45. struct branch_entry entries[];
  46. };
  47. /*
  48. * The hw_idx is only available when PERF_SAMPLE_BRANCH_HW_INDEX is applied.
  49. * Otherwise, the output format of a sample with branch stack is
  50. * struct branch_stack {
  51. * u64 nr;
  52. * struct branch_entry entries[0];
  53. * }
  54. * Check whether the hw_idx is available,
  55. * and return the corresponding pointer of entries[0].
  56. */
  57. static inline struct branch_entry *perf_sample__branch_entries(struct perf_sample *sample)
  58. {
  59. u64 *entry = (u64 *)sample->branch_stack;
  60. entry++;
  61. if (sample->no_hw_idx)
  62. return (struct branch_entry *)entry;
  63. return (struct branch_entry *)(++entry);
  64. }
  65. struct branch_type_stat {
  66. bool branch_to;
  67. u64 counts[PERF_BR_MAX];
  68. u64 cond_fwd;
  69. u64 cond_bwd;
  70. u64 cross_4k;
  71. u64 cross_2m;
  72. };
  73. void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
  74. u64 from, u64 to);
  75. const char *branch_type_name(int type);
  76. void branch_type_stat_display(FILE *fp, struct branch_type_stat *st);
  77. int branch_type_str(struct branch_type_stat *st, char *bf, int bfsize);
  78. #endif /* _PERF_BRANCH_H */