sample.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_SAMPLE_H
  3. #define __PERF_SAMPLE_H
  4. #include <linux/perf_event.h>
  5. #include <linux/types.h>
  6. struct machine;
  7. struct thread;
  8. /* number of register is bound by the number of bits in regs_dump::mask (64) */
  9. #define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
  10. struct regs_dump {
  11. u64 abi;
  12. u64 mask;
  13. u64 *regs;
  14. /* Cached values/mask filled by first register access. */
  15. u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
  16. u64 cache_mask;
  17. };
  18. struct stack_dump {
  19. u16 offset;
  20. u64 size;
  21. char *data;
  22. };
  23. struct sample_read_value {
  24. u64 value;
  25. u64 id; /* only if PERF_FORMAT_ID */
  26. u64 lost; /* only if PERF_FORMAT_LOST */
  27. };
  28. struct sample_read {
  29. u64 time_enabled;
  30. u64 time_running;
  31. union {
  32. struct {
  33. u64 nr;
  34. struct sample_read_value *values;
  35. } group;
  36. struct sample_read_value one;
  37. };
  38. };
  39. static inline size_t sample_read_value_size(u64 read_format)
  40. {
  41. /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
  42. if (read_format & PERF_FORMAT_LOST)
  43. return sizeof(struct sample_read_value);
  44. else
  45. return offsetof(struct sample_read_value, lost);
  46. }
  47. static inline struct sample_read_value *next_sample_read_value(struct sample_read_value *v, u64 read_format)
  48. {
  49. return (void *)v + sample_read_value_size(read_format);
  50. }
  51. #define sample_read_group__for_each(v, nr, rf) \
  52. for (int __i = 0; __i < (int)nr; v = next_sample_read_value(v, rf), __i++)
  53. #define MAX_INSN 16
  54. struct aux_sample {
  55. u64 size;
  56. void *data;
  57. };
  58. struct simd_flags {
  59. u8 arch:1, /* architecture (isa) */
  60. pred:2; /* predication */
  61. };
  62. /* simd architecture flags */
  63. #define SIMD_OP_FLAGS_ARCH_SVE 0x01 /* ARM SVE */
  64. /* simd predicate flags */
  65. #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */
  66. #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */
  67. struct perf_sample {
  68. u64 ip;
  69. u32 pid, tid;
  70. u64 time;
  71. u64 addr;
  72. u64 id;
  73. u64 stream_id;
  74. u64 period;
  75. u64 weight;
  76. u64 transaction;
  77. u64 insn_cnt;
  78. u64 cyc_cnt;
  79. u32 cpu;
  80. u32 raw_size;
  81. u64 data_src;
  82. u64 phys_addr;
  83. u64 data_page_size;
  84. u64 code_page_size;
  85. u64 cgroup;
  86. u32 flags;
  87. u32 machine_pid;
  88. u32 vcpu;
  89. u16 insn_len;
  90. u8 cpumode;
  91. u16 misc;
  92. u16 ins_lat;
  93. /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */
  94. u16 weight3;
  95. bool no_hw_idx; /* No hw_idx collected in branch_stack */
  96. bool deferred_callchain; /* Has deferred user callchains */
  97. u64 deferred_cookie;
  98. char insn[MAX_INSN];
  99. void *raw_data;
  100. struct ip_callchain *callchain;
  101. struct branch_stack *branch_stack;
  102. u64 *branch_stack_cntr;
  103. struct regs_dump *user_regs;
  104. struct regs_dump *intr_regs;
  105. struct stack_dump user_stack;
  106. struct sample_read read;
  107. struct aux_sample aux_sample;
  108. struct simd_flags simd_flags;
  109. };
  110. void perf_sample__init(struct perf_sample *sample, bool all);
  111. void perf_sample__exit(struct perf_sample *sample);
  112. struct regs_dump *perf_sample__user_regs(struct perf_sample *sample);
  113. struct regs_dump *perf_sample__intr_regs(struct perf_sample *sample);
  114. void perf_sample__fetch_insn(struct perf_sample *sample,
  115. struct thread *thread,
  116. struct machine *machine);
  117. /*
  118. * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
  119. * 8-byte alignment.
  120. */
  121. static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
  122. {
  123. return sample->raw_data - 4;
  124. }
  125. #endif /* __PERF_SAMPLE_H */